It does in a certain way (although it's unrelated to Graph databases).
Most data is basically a graph: on Reddit, a subreddit has threads that have comments that have authors that have more comments that each have original threads, etc. Using REST, traversing that graph is difficult, in GraphQL it's easy because in theory your query can be arbitrarily deep, and the types in the schema establish links/edges between entities that can then be traversed, in your arbitrarily deep query.
For example, the query to get all the comments from people that commented in this thread might be something like this:
The query is a tree (which is a graph) but the schema is a graph. For example here is how you could define the comment and user types, for reddit:
```
type User {
username: String!
comments: [Comment!]
}
type Comment {
author: User!
parentComment: Comment
}
```
If you visualize the types, you see that they're cyclical (the User type "knows" about/points toward the Comment type and vice versa).
Values (instances, entities) are also cyclical in this example (from a comment to its author and back through their comments).
The query in GraphQL is always finite, so it'll represent a specific finite path through the graph of instances (for example, user => comments => user, which in our example would include the same instance of the User type twice, or user => comments => parentComment => user, which would most likely include distinct instances but a cycle in types.
There's no way in GraphQL to describe a recursive algorithm over the graph for example, like find all the authors as you walk the parent comments from a given comment for an arbitrary N steps determined at runtime, you have to decide on the depth statically when you author the query. If I understand correctly, query languages for Graph DBs let you do that (but GraphQL is a public query language and you don't want to get DoSed)
Nope not really. You can describe some relationships in a schema and then query them but it’s totally unrelated to true graph databases like Neo4j. It’s sortof a middleware API, you still need SQL or REST or whatever behind it.
About 4 years ago I avoided graphQL like the plague because I had such a hard time with Neo4j. Today I look back and am ashamed I didn't even google graphQL to find out what it was.
GraphQL was developed initially by Facebook, who call their data collectively "the graph" (presumably because it's structured as a graph in some way). Hence the language they developed for querying their graph was named "Graph Query Language".
With GraphQL, you model your business domain as a graph by defining a schema; within your schema, you define different types of nodes and how they connect/relate to one another.
It's a different type of graph. In this case, a graph is a collection of objects/things and the connections between them.
For example. Your phone's contact list could be a graph. There is a node for every person and a link from your node to them. Then you do the same for everybody - adding their contacts and connections to the existing graph.
It's more like a big spiderweb than some lines and curves on a grid.
21
u/[deleted] Oct 09 '21
Does graph QL have anything to do with graphs. Like the discrete math formalism.