Live data from Hacker News

GraphQL: A data query language

code.facebook.com

11–20 of 84 posts

Re: GraphQL: A data query language

#12
post #10

I keep hearing people say things along the lines of, "Relay looks great, but I don't want to store my data in a graph". My impression is that GraphQL has nothing to do with graphs, really - it's a bit more like SchemaQL if anything. Could someone from the facebook team clarify about the name?

Yep, GraphQL is agnostic as to how your data is stored. For example, https://github.com/graphql/swapi-graphql/ is a GraphQL schema that is backed by the swapi.co API. The examples at https://github.com/graphql/graphql-js/blob/master/src/__test... are backed by in-memory JSON objects. At Facebook, we have GraphQL types backed by data stored in a number of backends, including types backed by SQL tables.

Re: GraphQL: A data query language

#13

Are there still problems with GET requests not allowing very much data in the request? Will I have to send this as a POST, or is that all 200x?

If you look at facebook's Relay implementation the graphql queries are indeed sent as POSTs.

https://github.com/facebook/relay/blob/master/src/network-la...

Re: GraphQL: A data query language

#16

Why mirror the structure, but not syntactic details, of JSON (or YML) in the pretty printing? It's true that we've passed peak colon as a culture, and need to start reimagining life in a post-colonial way, but...

GraphQL queries are hierarchical so that the response mirrors the structure of the query. We found that there were needs of the query (query parameters and directives, for example) that didn't feel ideally represented in JSON, which is why we have a different syntax.

We've got a reference lexer and parser in JS at https://github.com/graphql/graphql-js/tree/master/src/langua..., and we have a parser in C++ with C and C++ APIs (that can be used to build a parser for other languages) at https://github.com/graphql/libgraphqlparser.

Re: GraphQL: A data query language

#17

Are there still problems with GET requests not allowing very much data in the request? Will I have to send this as a POST, or is that all 200x?

Are you talking about the size limit (of about 2000 chars) on url strings? That's not a GraphQL thing, that's a limit imposed by certain browsers. If your request data might be bigger then it needs to be in a POST.

> If your request data might be bigger then it needs to be in a POST.

Ok. I was hoping things had gotten better.

Re: GraphQL: A data query language

#18

I wonder how access controls will work in GraphQL/Relay.

The GraphQL API acts as a layer atop application code; it assumes that the application code takes care of any access controls (since those access controls would apply to anyone querying that data, not just GraphQL). So there's nothing for access control built-in to GraphQL, but GraphQL can map to arbitrary access controls that exist in the application layer.

The GraphQL server can pass down authentication information through the query using `rootValue` (for example, it might pass the OAuth access token that the client provided in the request), which the mapping from GraphQL-to-application-code can pass to the application code's access controls.

Re: GraphQL: A data query language

#19
post #10

I keep hearing people say things along the lines of, "Relay looks great, but I don't want to store my data in a graph". My impression is that GraphQL has nothing to do with graphs, really - it's a bit more like SchemaQL if anything. Could someone from the facebook team clarify about the name?

Yep, GraphQL is agnostic as to how your data is stored. For example, https://github.com/graphql/swapi-graphql/ is a GraphQL schema that is backed by the swapi.co API. The examples at https://github.com/graphql/graphql-js/blob/master/src/__test... are backed by in-memory JSON objects. At Facebook, we have GraphQL types backed by data stored in a number of backends, including types backed by SQL tables.

I'd like to read more about the backing data stores. If you're aggregating data across a lot of different stores, it seems you could easily add what looks like a tiny piece of data to your query, but, in truth, is much more expensive on the backend.

Re: GraphQL: A data query language

#20
post #14

What about inequality operators (>, >=, What about complex predicates (and, or)? The language seems rather limited.

When building out a GraphQL schema, the schema developer chooses which functionality to expose to the client. So rather than having the client do operations or predicates directly, the server declares what functionality is available, and might expose functionality that ordinarily would have used operators or predicates.

For example, we might have the following query on Facebook's GraphQL schema:

  {
    user(id: 4) {
      followers(isViewerFriend: true, birthdaysInRange: {before: -2, after: 2} orderBy:NAME) {
        name
      }
    }
  }
EDIT: fix code formatting

Which fetches Zuck's followers, and filters it to only my friends, and only those friends whose birthdays are within two days of today, and then orders them by name.

The `isViewerFriend`, `birthdaysInRange` and `orderBy` parameters were explicitly added to the API by the API developer for clients to use.

So clients don't have the ability to do arbitrary operators, but we also know that the client is only using functionality in the API that the API developer chose explicitly to allow.

Post reply on HN