graphql-client icon indicating copy to clipboard operation
graphql-client copied to clipboard

GraphQL::Client silently accepts and fixes invalid queries

Open cjoudrey opened this issue 7 years ago • 2 comments

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

cjoudrey avatar Jul 19 '18 14:07 cjoudrey

References https://github.com/github/graphql-client/issues/75

josh avatar Jul 24 '18 20:07 josh

Does the protocol specify the expected behavior in this use-case?

belt avatar Jun 11 '19 15:06 belt