Skip to content

Implement toString() to support graphql.js #206

@Pokute

Description

@Pokute

Issue Labels

  • has-reproduction
  • feature
  • [] docs
  • blocking
  • good first issue

/label graphql.js

graphql-tag claims to be a utility for graphql, but doesn't have any indication on how to use it with graphql package. Sure enough the result from graphql-tag might be valid AST, but the I don't think that the specifications really make any mention of queries being in AST format. Graphql doesn't support gql objects as query parameter.

const someQuery = gql`
  query { something { else } }
`

console.log(someQuery.toString()); // "[object Object]"
graphql(schema, someQuery); // Fails.

someQuery.toString() = function() { return this.loc.source; };
console.log(someQuery.toString()); // Proper query string.
graphql(schema, someQuery); // Works.

This should be really easy to implement with the objects returned by the template stringy adding a custom toString() -function to them. Currently the default is always returns "[object Object]".

If above change is unacceptable, there should be documentation how to properly retrieve the query in string form.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew addition or enhancement to existing solutionsgood first issueIssues that are suitable for first-time contributors.graphql.js

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions