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 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
Customising your server configuration
Graphback enabled applications use GraphQL Config to let you control your GraphQL application. Graphback specific customisations are specified in the
graphback extension. See Config to learn how you can customise your Graphback project configuration.
GraphQL Serve is fully compatible with GraphQL Config. Running
gqlserve [subcommand] in the same directory as your
.graphqlrc file will use the Graphback configuration section to find your model directory, configure global CRUD methods and execute the plugin sequence.