parse-server icon indicating copy to clipboard operation
parse-server copied to clipboard

Make GraphQL schema overridable

Open richardguerre opened this issue 4 years ago • 5 comments

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

Currently working with Float instead of Int but would prefer to have a clear distinction between actual Floats and Ints.

richardguerre avatar Oct 15 '21 12:10 richardguerre

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.

Moumouls avatar May 01 '22 12:05 Moumouls

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

Moumouls avatar Nov 01 '22 22:11 Moumouls

What would you suggest how to proceed with this?

mtrezza avatar Nov 01 '22 23:11 mtrezza