graphql-client
graphql-client copied to clipboard
GraphQL::Client silently accepts and fixes invalid queries
GraphQL requires sub-selections on object/interface/union type fields.
For example, given this schema:
type Query {
repository(owner: String!, name: String!): Repository
}
type Organization {
id: ID!
}
type Repository {
organization: Organization
}
This query is not valid:
{
repository(owner: "rails", name: "rails") {
organization
}
}
I'm not sure if this was intended, but GraphQL Client silently adds __typename to empty selection sets of fields that return an object type turning that invalid query into a valid one:
{
repository(owner: "rails", name: "rails") {
organization {
__typename
}
}
}
I think this behavior is misleading as it makes people think the query they crafted is valid. It creates confusion when they then try run this same query outside of GraphQL Client (i.e. GraphiQL or tests) it fails.
I don't think GraphQL Client should be fixing these malformed queries, but I could be missing context on why this was done initially.
cc @arthurschreiber
References https://github.com/github/graphql-client/issues/75
Does the protocol specify the expected behavior in this use-case?