Reputation: 560
Brand new to GraphQL. It's my understanding that it is a query language for APIs. Ok, I get that.
Reading today, GraphQL can be used with a DB but it doesn't require one. The latter part of this is what I don't understand.
Where is this data stored if no DB is in place?
Upvotes: 1
Views: 1131
Reputation: 84807
From the spec:
GraphQL does not mandate a particular programming language or storage system for application servers that implement it. Instead, application servers take their capabilities and map them to a uniform language, type system, and philosophy that GraphQL encodes.
A GraphQL response consists of one or more fields. The schema of the GraphQL service being queried describes what fields are available and what arguments can be provided to those fields. However, the GraphQL service has to also provide code to resolve those fields (i.e. provide a value for it). How this code fetches the value for the field, as well as what side effects it may also result in, is entirely up to the service.
Here's a simple example. Let's say we have the following schema:
type Query {
helloWorld: String
}
This would let us write a query like:
query {
helloWorld
}
In order for helloWorld
to resolve to something other than null
, we would also provide a resolver function for it:
function resolve (root, args, ctx, info) {
return "Hello world!"
}
Here, we've hard-coded the value that will be resolved. We could get the value in any number of ways, though. For example:
A GraphQL service typically interacts with a database or some API, but there are services that interface with message queues, IMAP inboxes, blockchains and more. So your data could literally come from just about anywhere.
Upvotes: 1