realm / realm-graphql-service

GraphQL service for Realm Object Server
https://realm.io
Apache License 2.0
43 stars 10 forks source link

GraphQL Internal Error #59

Closed howdyhyber closed 6 years ago

howdyhyber commented 6 years ago

We upgraded our server from 3.4.2 to 3.6.12, and we are experiencing some issue something like this.

Internal server error: Error: Field Query.taskTemplates can only be defined once. Field Mutation.deleteTaskTemplates can only be defined once. Field Subscription.taskTemplates can only be defined once. at assertValidSchema (/home/ubuntu/spingine/node_modules/graphql/type/validate.js:82:11) at Object.validate (/home/ubuntu/spingine/node_modules/graphql/validation/validate.js:58:35) at doRunQuery (/home/ubuntu/spingine/node_modules/apollo-server-core/dist/runQuery.js:110:38) at /home/ubuntu/spingine/node_modules/apollo-server-core/dist/runQuery.js:21:56 at at process._tickCallback (internal/process/next_tick.js:188:7)

How do we solve this?

nirinchev commented 6 years ago

It appears as if the GraphQL service is creating duplicate definitions for the TaskTemplate class. Can you open this realm in Studio and verify that it doesn't have duplicate tables? If it doesn't, can you share the Realm file so we can examine it locally and try to reproduce?

howdyhyber commented 6 years ago

In our Realm Path, there is TaskTemplate Class, and there is TaskTemplates class. We did use query something in this class because we no longer use this.

nirinchev commented 6 years ago

Okay - this is a problem then, because the GraphQL service assumes that classes are named with singular nouns. Pluralizing TaskTemplate and TaskTemplates results in the same string which will then cause ambiguity. This is not a change with latest ROS though - it has always been a limitation, so not sure how it has worked before the upgrade.

howdyhyber commented 6 years ago

what possible fix can we do to this matter?

nirinchev commented 6 years ago

Unfortunately nothing comes to mind - the assumption that classes are singular and PascalCase-d affects a lot of the schema generation code, so I don't think I can make a change without breaking every consumer.

It would be easiest if you could discard that Realm file and start from scratch. If that doesn't work for you (e.g. because it's used in production and there are users who depend on it), you could probably fork the GraphQL service and make the changes necessary to support your use case - e.g. if you don't use the TaskTemplate class anymore, you could filter it out in the schema generation code here:

https://github.com/realm/realm-graphql-service/blob/master/src/service.ts#L417

howdyhyber commented 6 years ago

Ahh okay well try this on our end.

howdyhyber commented 6 years ago

@nirinchev This solves our problem. Thanks :tada:

nirinchev commented 6 years ago

Glad to hear that! Unfortunately, I don't think I can enable this in a generic way without breaking existing consumers. I've opened an issue to track progress toward lifting these assumptions: https://github.com/realm/realm-graphql-service/issues/60.