Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GraphQL schema name collision caused by autogenerated Order input parameter #8802

Open
4 tasks done
ThunbergOlle opened this issue Nov 9, 2023 · 1 comment
Open
4 tasks done
Labels
type:feature New feature or improvement of existing feature

Comments

@ThunbergOlle
Copy link

ThunbergOlle commented Nov 9, 2023

New Issue Checklist

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

  1. Create a new parse project with GraphQL
  2. Create a class called Item
  3. 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
  }
}
Copy link

parse-github-assistant bot commented Nov 9, 2023

Thanks for opening this issue!

  • 🚀 You can help us to fix this issue faster by opening a pull request with a failing test. See our Contribution Guide for how to make a pull request, or read our New Contributor's Guide if this is your first time contributing.

@mtrezza mtrezza added the type:feature New feature or improvement of existing feature label Nov 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:feature New feature or improvement of existing feature
Projects
None yet
Development

No branches or pull requests

2 participants