With GraphQL Serve you can have a GraphQL API running in just a few seconds without writing a single line of code - all you need is a data model
GraphQL Serve is a CLI tool that leverages the power of Graphback to generate a codeless Node.js GraphQL API complete with schema and CRUD resolvers and a MongoDB database in-memory.
You can install
graphql-serve globally with npm:
The bare minimum you need is a GraphQL file with your data models. Create a file called
Note.graphql and add the following:
@model annotation indicates that
Note is a data model and Graphback will generate resolvers, a CRUD service and data source for it. You can learn how to build more complex data models in Data Model.
Running your codeless GraphQL server
To start your server, run the following command from the same directory as
This will start a GraphQL server on a random port using the data models we just added.
You can customise the directory of the data models:
You can also specify where to load the data models from with a Glob pattern:
You can specify which port to start the server on:
Printing your GraphQL schema
Graphback receives your data models as an input and processes them to generate a GraphQL schema complete with additional types, queries, mutations and subscriptions.
GraphQL Serve allows you to print the resulting schema in your terminal with the