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

Add example of variable coercion failure #289

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions spec/GraphQLOverHTTP.md
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,18 @@ If
raises a _GraphQL request error_, the server SHOULD NOT execute the request and
SHOULD return a status code of `200` (Okay).

For example the well-formed GraphQL-over-HTTP request:

```json
{
"query": "query getItem($id: String!) { item(id: $id) { id } }",
Copy link
Member

@spawnia spawnia Feb 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"query": "query getItem($id: String!) { item(id: $id) { id } }",
"query": "query ItemName($id: ID!) { item(id: $id) { id name } }",

The example works fine as is. However, I think it is more common to use PascalCase for operation names, and I also think it is best practice to use the ID type for identifiers.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is more common to use PascalCase for operation names

Perhaps; but I usually see schemas that follow this: https://www.apollographql.com/docs/technotes/TN0002-schema-naming-conventions/

I also think it is best practice to use the ID type for identifiers.

Agree

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://www.apollographql.com/docs/technotes/TN0002-schema-naming-conventions/ does not explicitly talk about operation names, but its examples do use PascalCase (query Products).

Copy link
Member

@benjie benjie Feb 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually went through the spec and extracted the conventions from that; results are here:

https://benjie.dev/graphql/naming

The spec uses a mixture for operation names but camelCase is more common than UpperCamelCase. You may find the part on fragments interesting because I had a conversation with Lee about it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tweaked your example and committed that, I added a get prefix to match spec examples such as getDogName https://spec.graphql.org/draft/#example-069e1

"variables": { "id": null }
}
```

would fail variable coercion as the value for `id` would fail to satisfy the
query document's expectation that `id` is non-null.

##### Field errors encountered during execution

If the operation is executed and no _GraphQL request error_ is raised then the
Expand Down