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

[Feature request] Provide parse, compile, merge and check functions #143

Closed
gyzerok opened this Issue Aug 20, 2015 · 3 comments

Comments

Projects
None yet
3 participants
@gyzerok

gyzerok commented Aug 20, 2015

It would be cool if you can provide functionality for parsing, merging and compiling GraphQL queries. So not only Relay can use awesome features of GraphQL.

  1. parse function should parse GraphQL query string into structure like info object which you can get in resolve function.
  2. compile function should be an opponent for parse
  3. merge function should merge two info objects to later perform optimised query to the server.

Consider this example:

query FirstQuery {
  ... on Root {
    todos: todos(count: 5) {
      _id,
      text
    }
  }
}

query SecondQuery {
  ... on Root {
    todos: todos(count: 6) {
      _id,
      createdAt
    }
  }
}

Using suggested functions it can be merged in:

query OptimizedQuery {
  ... on Root {
    todos: todos(count: 6) {
      _id,
      text,
      createdAt
    }
  }
}

@gyzerok gyzerok changed the title from [Feature request] Provide parse, merge and compile functions to [Feature request] Provide parse, compile, merge and check functions Aug 22, 2015

@gyzerok

This comment has been minimized.

gyzerok commented Aug 22, 2015

Also it would be nice to have check function to be able to check query against schema to know if it is valid.

@Nexi

This comment has been minimized.

Nexi commented Aug 22, 2015

+1

@nemanja-stanarevic

This comment has been minimized.

Contributor

nemanja-stanarevic commented Sep 4, 2015

They expose parser and AST visitor as public API and you can import parse and visit from graphql/language. Parse will give you Abstract Syntax Tree that you can walk through with visit. In-code documentation for visitor is great (see language/visitor.js), but post if you have any questions.

Finally, you can import validate and specifiedRules from graphql/validation and run query AST and schema definition through it to make sure everything is copacetic.

As far as query optimization goes, I defer to graphql team, but wouldn't think it make sense to have that in the reference implementation. It is perhaps a layer you have in between GraphQL endpoint and data store that caches and consolidates redundant queries, see Haxl for inspiration.

@leebyron leebyron closed this in 4547904 Feb 3, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment