Due to how extend works we can't replace type fields
See original GitHub issueSo I was given this project a first try since I’m building some sort of boilerplate. I already have a schema, with (most) resolvers in place and I wanted to extend this with mock data. I’m assuming this scenario is probably not the goal for this project, but certainly seems like it can be used for it, and yet it can’t.
I can’t replace fields within the existing types since extendSchema
from graphqljs seems to complain. In this case what I’d like is to leave the schema as is, but replace the resolver instead.
Example: Original schema:
type User {
id: ID!
firstName: String
lastName: String
}
Our fake schema in extend mode:
extend type User {
firstName: String @fake(type: firstName)
lastName: String @fake(type: lastName)
}
I would have expected the above syntax to work, and the resolver within it to return me the fake fields. I feel like I’m missing something obvious but if this isn’t supported I think it should. I’d be able to help if you can point me in the right direction.
EDIT:
I’ve done something like this in the past with addMockFunctionsToSchema
from graphql-tools
but obviously, that one lacks the Faker integration, and it’s also hard to do proper relay connections in there. Maybe we could find a way to use it here as a last resort, but I think custom resolvers after leaving the schema in place should be the way to go.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:8
- Comments:18 (5 by maintainers)
@ahmedlhanafy Not ATM, it’s just a proposed solution. I will try to find time to implement it this month
I made NPM module based on my PR which enables fields overriding. If you need this feature in main module, you can subscribe to my PR’s notifications and use my fork-module until it gets merged.
https://www.npmjs.com/package/@proscom/graphql-faker