parse-community / parse-server

Parse Server for Node.js / Express
https://parseplatform.org
Apache License 2.0
20.95k stars 4.78k forks source link

Make GraphQL schema overridable #7636

Open richardguerre opened 3 years ago

richardguerre commented 3 years ago

New Feature / Enhancement Checklist

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

  1. Create a class, MyClass, with a field of type Number
  2. 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
<!-- Which alternatives or workarounds exist currently? -->
Currently working with `Float` instead of `Int` but would prefer to have a clear distinction between actual `Float`s and `Int`s.
parse-github-assistant[bot] commented 3 years ago

Thanks for opening this issue!

Moumouls commented 2 years ago

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:

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.

Moumouls commented 2 years ago

btw @mtrezza this feature is supported but not correctly documented yet.

mtrezza commented 2 years ago

What would you suggest how to proceed with this?

Moumouls commented 1 month ago

I need to send a Documentation PR on this @mtrezza since it's supported and super useful