Skip to content

possible GraphQL::Query refactor #956

Closed
@xuorig

Description

@xuorig

Right now it's possible for an instance of GraphQL::Query to be in an invalid state. For example Take this query:

document = GraphQL.parse('{ some { query } }')

query = GraphQL::Query.new(
  query: "{ another { query } }"
  document: document
)

This ends up being valid, { some { query } } being executed.

Right now the API for GraphQL::Query is a bit confusing. A query can be provided through:

  • the second argument
  • the query kwarg
  • a pre parsed graphql document

The outcome is not obvious to the user 😁

In the spirit of making it hard to do the wrong thing, what would you think if we provided an interface that exposes the two ways of building queries through their own separate ways?

Maybe Query.new can only take document, and then we can also expose Query.from_query_string / Query.from_document ?

A quick fix would be to make the runtime check for query && document (I remember we had that a while ago, but might have been lost?) but I have a feeling we can probably make it better with something like what i proposed! (Although it might be a slight breaking change 😁 (1.7.0 ? 🐒 )

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions