parse-community / parse-community/parse-server

Make GraphQL schema overridable

Open
#7,636 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type:docs
Dominant language
JavaScript
Stars
21.4k
Forks
4.8k
Avg merge
7h 45m
Merged PRs (30d)
11

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in lib/GraphQL/ParseGraphQLSchema.js around ParseGraphQLSchema.load, then reproduce the MyClass example with an existing Number field and an Int extension. Trace the schema stitching and extension validation shown in the error. Done means existing GraphQL field types can be overridden, including the NumberWhereInput fields, without the duplicate-field error.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, javascript
Domain
api, backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.