3 ms·
GraphQL can be totally be used to represent and query true graphs, not just trees. The data gets materialized into nested JSON (which can be thought of as a tre
by henryfjordan 7y ago
GraphQL can be totally be used to represent and query true graphs, not just trees. The data gets materialized into nested JSON (which can be thought of as a tree) but that doesn't mean it doesn't represent a graph.
Other than that though, you are quite correct, the two do not serve the same purpose.
Neo4j has an extension that exposes a GraphQL API that converts the queries to Cypher (https://neo4j.com/developer/graphql/#neo4j-graphql-java https://neo4j.com/developer/graphql/#neo4j-graphql-java). I've used it for some basic things but for anything complex you need to be careful and inspect the queries it produces.
- frant-hartm 7y agoHow would you query for a path or cycle of arbitrary length in GraphQL?
- henryfjordan 7y agoYou cannot do that directly out-of-the box, but you can write your server to include directives for that. See some discussion here: https://github.com/graphql/graphql-spec/issues/91 https://github.com/graphql/graphql-spec/issues/91 Also just because you cannot query at arbitrary depths doesn't mean that GraphQL doesn't work with graphs, just that it might be a poor choice of tool for that work.
- prashnts 7y agoThank you, everyone in this thread! These are some helpful insights.
- FridgeSeal 7y agoDGraph is perfectly capable of doing these with a query language extremely similar to GraphQL (and as of v2 will natively support GraphQL): https://docs.dgraph.io/master/query-language/#k-shortest-path-queries https://docs.dgraph.io/master/query-language/#k-shortest-pat...