Learn GraphQL with GitHub
github.com
github.com
Through graphql I want to find my first ancestor following all mothers backwards. The query would be:
query familyTree {
name,
mother {
name,
mother {
..and so on for an unknown number of nestings
}
}
}
Dataloader solves batching of the nested query on the server, but doesn't solve the problem of not knowing what the correct number of nestings the query should have.Of course it's possible to create a new graphql endpoint for this type of query, but then we've just recreated REST in graphql.
Your mother field should resolve to a Person type, with a mother and/or ancestors field, which would be a graphql list type of the Person type.
Something like this:
Person {
mother: Person
femaleAncestors: [Person]
}``` Person { ancestors(gender: Female, orderby: [AGE], first: 10) { node { name } } } ```
I do see how nested objects might look like a perfect fit for this, since families are literally "nested objects". Perhaps there are plenty of advantages to using NoSQL and shaping the data this way... but the thought of creating an API With that structure is terrifying to me, haha.
Question to OP: are you using this structure for a live api/website I can take a look at? Does each node have an absolute ID? Do you normalize your data? Maybe I'm thinking too much in relational terms here? I'm genuinely curious about this.
[1]: https://netflix.github.io/falcor/documentation/jsongraph.htm...
GraphQL excels at nested data structures. When you have infinitely recursive child nodes of the same type (like ancestors in a family tree) the GraphQL list type should be used.
As for schema-less we generate a scheme that includes all types and fields but we filter out any non-available ones (according to user with) each time an introspection query is issued.
Scroll down to the hands on tutorials, the ones on the right are server-side tutorials. I still recommend you read through the beginner material as well!
Sure! But here's the thing to know: the meat of a GraphQL server is in the schema. Every server implementation you see will have you define a schema, and then will execute queries against it. I would do the setup for the implementation in the language of your choice (instructions for which is usually listed in the README of the git repo), and then take a look at example schema, the most famous of which is the Star Wars schema:
For JS: https://github.com/jahewson/graphql-starwars
For Python (Graphene): https://github.com/graphql-python/graphene/tree/master/examp...
> interpreting complex queries as SQL/NoSQL queries in a performant way
Something which is often confusing is that GraphQL is completely database agnostic. However you were fetching data from your database of choice before, you will continue to do. GraphQL has you define types (i.e. a user type, a blog post type, etc.), and then you tell it how to fetch that data. It could be a library for SQL, NoSQL, or even another API.
For example, imagine I define my GraphQL schema which is pretty similar to another GraphQL schema (of a remote API server).
Could I implement my GraphQL server's resolvers in such a way that they simply rewrite/reinterpret the incoming query by forwarding the (modified) query to the target remote GraphQL server? Or will it be very inefficient and very hard to write this kind of GraphQL-schema-to-similar-GraphQL-schema adapter?
To compare REST, one can imagine (a part of) your REST API being similar to another external REST API. It's relatively straightforward to have your HTTP handlers map to remote REST API endpoints and make the neccessary conversions. (Assuming your REST endpoints map relatively 1:1 to the other API's REST endpoints).
Hopefully my question makes sense...
So in other words, for parts of your schema that are similar to each other, you'd simply include and compose together the relevant resolver functions for the fields they share. The conceptual model is similar to reducer composition in Redux, where top-level reducers (analogous to the root query resolver in GraphQL) can delegate to child reducers each responsible for only a part of the application state (or child resolvers each responsible for resolving a single fragment of the whole query), and this delegation can continue to arbitrary depths.
EDIT: I see your question is actually about composing with third party GraphQL APIs, so I haven't really answered it. GraphQL resolvers are just functions that return data. So you can certainly just implement an async resolver that forwards the received GraphQL query to a remote API of interest, and take the response returned and merge/override it with additional data to form the response to your own query.
If you just want to grab an object for a certain edge than that's easy. Routing the entire query differently based on something at the root would also be easy, but routing it based on something deeply nested might be trickier, but still not too tricky.
https://news.ycombinator.com/item?id=14896809
This all could make it very easy to write a GraphQL server backed by Rezoom + Rezoom.SQL.
https://github.com/rspeele/Rezoom
https://github.com/rspeele/Rezoom.SQL
--
If there are any other resources I'm not aware of, please let me know!
[1] https://developer.github.com/v4/
https://github.com/theogravity/graphql-apollo-server-client-...
I actually have stopped using Apollo on the server side (outside of the middleware) to build the GraphQL definitions.
I use the vanilla graphql-js lib instead with the join-monster library for queries + batching + paging and objection.js for modeling + mutations.
join-monster is built for using your database with graphql (I use postgres). Objection.js is great for mutations because of its insertGraph / upsertGraph functionality, where you can feed in your entire mutation input as a nested structure and it will perform the right insertion queries to multiple tables based on your objection.js models that you've defined.
I've learned much more since then (eg authorization / authentication / mutations / implementing paging via relay connections) that I'll probably start up another project in the future talking about how to build a full-scale GraphQL server.
I'd just like to download the video directly, if at all possible.
https://resources.github.com/webcasts/GitHub-communicating-w...
With some digging you can get an MP4.
For everybody interested who already wants to get familiar with GraphQL, check out this getting started tutorial for GraphQL: https://www.howtographql.com/