Step 5: GraphQL server
The fastest way toward GraphQL
Vulcan key feature is its ability to create a full-fledged API based on your models. More precisely, Vulcan relies on GraphQL, thanks to Apollo Server.
- You get a single endpoint,
/api/graphql
, to fetch all your data - You write queries using the GraphQL language
Vulcan generates basic CRUD queries for all your models
- queries to get data (single item or "multi" list). Vulcan's powerful filter system let's you select only the documents you want.
- mutations to manipulate data (create, update, delete).
Check š„Vulcan Fire documentation for more info.
Merge with a custom schema
In Vulcan Next, you are always allowed to not use Vulcan. This means that you can also write a custom GraphQL backend using the traditionnal syntax described in Apollo Server documentation.
Open src/pages/api/graphql.ts
.
In this file, we setup an Apollo GraphQL server. The only specifity, is that we merge the GraphQL schema with a schema automatically generated by Vulcan.
That's why we want you to always export your server models in src/core/models.server
, this way relevant resolvers are automatically added
to the GraphQL schema.
See the schema
Vulcan comes with GraphqQL Playground and GraphQL Voyager installed.
Those awesome tools let you explore your schema and play around with your GraphQL server.
Go to step 6
Run the query:
And then answer this question:
- How many users to you get, as a logged out guest user? (click on the right answer)
- 1, the admin that has been seeded on application startup
- 0, because you are not logged in yet, and the User model permissions disallow reading for anonymouse users
- 42, because why not
(Hint: if you open Compass, you should see an admin user in your Mongo database. But does that mean that you can list users in your Vulcan Next app?)