Make GraphQL schema overridable
New Feature / Enhancement Checklist
- [x] I am not disclosing a vulnerability.
- [x] I am not just asking a question.
- [x] I have searched through existing issues.
Current Limitation
When trying to tighten the GraphQL type definitions by example changing a Parse number field to be Int instead of Float in the GraphQL schema.
Currently getting this error in the server logs, when trying to override a number field with type Int:
error: Error: Field "MyClass.numberField" already exists in the schema. It cannot also be defined in this type extension.
at assertValidSDLExtension (/parse-server/node_modules/graphql/validation/validate.js:124:11)
at Object.extendSchema (/parse-server/node_modules/graphql/utilities/extendSchema.js:77:43)
at /parse-server/node_modules/@graphql-tools/stitch/index.cjs.js:1232:28
at Array.forEach (<anonymous>)
at stitchSchemas (/parse-server/node_modules/@graphql-tools/stitch/index.cjs.js:1231:16)
at ParseGraphQLSchema.load (/parse-server/lib/GraphQL/ParseGraphQLSchema.js:212:56)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async ParseGraphQLServer._getGraphQLOptions (/parse-server/lib/GraphQL/ParseGraphQLServer.js:61:17)
at async /parse-server/lib/GraphQL/ParseGraphQLServer.js:99:86
Feature / Enhancement Description
Allow overriding of existing field types in the GraphQL schema.
Example Use Case
- Create a class, MyClass, with a field of type Number
- Extend graphql schema by adding
extend type MyClass {
numberField: Int
}
# If I also know that all my numbers are all integers, then I can do this too:
extend input NumberWhereInput {
equalTo: Int
notEqualTo: Int
lessThan: Int
lessThanOrEqualTo: Int
greaterThan: Int
greaterThanOrEqualTo: Int
in: [Int]
notIn: [Int]
}
Alternatives / Workarounds
Currently working with Float instead of Int but would prefer to have a clear distinction between actual Floats and Ints.
Thanks for opening this issue!
- 🎉 We are excited about your ideas for improvement!
Hi @richardguerre i can suggest switching to a code first graphql schema. I heavily use GraphQL Schema override extension. I worked a lot on the parse-server implementation to achieve what you are searching for.
You can choose your favorite code first GraphQL Schema tool (ex: nexus).
You can find some example on one of my open source repo:
- https://github.com/Moumouls/parse-next-mono-starter/tree/master/packages/back/src/customSchema
- https://github.com/Moumouls/parse-next-mono-starter/blob/master/packages/back/src/server.ts
You can see on this file https://github.com/Moumouls/parse-next-mono-starter/blob/master/packages/back/src/customSchema/types/User.ts that i override the "email" field with a custom "EmailSclaer". You can use the same strategy to override your Float fields with Int fields.
btw @mtrezza this feature is supported but not correctly documented yet.
What would you suggest how to proceed with this?