parse-community / parse-community/parse-server
GraphQL schema name collision caused by autogenerated `Order` input parameter
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 21.4k
- Forks
- 4.8k
- Avg merge
- 7h 45m
- Merged PRs (30d)
- 11
Description
New Issue Checklist
- I am not disclosing a vulnerability.
- I am not just asking a question.
- I have searched through existing issues.
- I can reproduce the issue with the latest version of Parse Server.
Issue Description
When autogenerating the GraphQL schema, Parse creates input types for each class. All the generated input types has a trailing Input word. Except for the Order input type. Meaning that if you have a class called Item the sorting input type will be called ItemOrder
This becomes problematic since it is common, when for example, building e-commerce sites, to have collections ending with "Order" (as in buy-order). ItemOrder, GiftCardOrder etc.
Because of this, if you have two classes called Item and ItemOrder it will cause a name collision in the schema. The result of this being that ItemOrder (the collection) defaults its type to Object causing an error when trying to access its collection properties through the GraphQL API.
Here is an example of how creating a class called Item reserving the type name ItemOrder
items(
where: ItemWhereInput
order: [ItemOrder!]
skip: Int
after: String
first: Int
before: String
last: Int
options: ReadOptionsInput
): ItemConnection!
If we also have a ItemOrder collection, it logs this warning:
warn: Type ItemOrder could not be added to the auto schema because it collided with an existing type.
And the type for the ItemOrder (collection) query is:
itemOrder(
id: ID!
options: ReadOptionsInput
): Object
Steps to reproduce
- Create a new parse project with GraphQL
- Create a class called Item
- Create a class called ItemOrder
Solutions
A potential solution is to follow the naming conventions parse already uses for the other input types. Meaning that we can add Input to the end.
Example:
items(
where: ItemWhereInput
order: [ItemOrderInput!]
skip: Int
after: String
first: Int
before: String
last: Int
options: ReadOptionsInput
): ItemConnection!
It should be noted that this is a breaking change if the input type is being used as follows:
query myQuery($order: [ItemOrder!]){
items(order: $order){
count
}
}
This would have to be changed to this:
query myQuery($order: [itemOrderInput!]){
items(order: $order){
count
}
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with Parse Server's GraphQL schema autogeneration and reproduce the collision using classes named Item and ItemOrder. Check how the ItemOrder sorting input type is named and how the conflicting collection type is handled. Done means the generated schema avoids the collision and the affected query types remain usable, with the breaking naming change documented or covered by tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, javascript, node.js
- Domain
- api, backend-api-design
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100