Getting Started with Hello World Data Sync
In this example, you add the Data Sync Server library to your Express node.js project, create an index-1.js
file, run the server, and query GraphQL.
-
Data Sync Server is a set of Node.js libraries that can be used to build a Data Sync server.
-
Data Sync Server is the starting point for developing a Data Sync application.
-
You have Node.js and npm installed.
-
You have created a
node.js
project.
-
Add libraries to your Node.js application:
$ npm install graphql (1) $ npm install express (2) $ npm install @aerogear/voyager-server (3)
1 See https://graphql.org/ 2 See https://expressjs.com/ 3 The Data Sync Server library that enables data sync -
Create an
index-1.js
file with the following content:const express = require('express') //Include our server libraries const { VoyagerServer, gql } = require('@aerogear/voyager-server') //Provide your graphql schema const typeDefs = gql` type Query { hello: String } ` //Create the resolvers for your schema const resolvers = { Query: { hello: (obj, args, context, info) => { return `Hello world` } } } //Initialize the library with your Graphql information const apolloServer = VoyagerServer({ typeDefs, resolvers }) //Connect the server to express const app = express() apolloServer.applyMiddleware({ app }) app.listen(4000, () => console.log(`🚀 Server ready at http://localhost:4000/graphql`) )
-
Run the server:
$ node index-1.js 🚀 Server ready at http://localhost:4000/graphql
-
Browse
http://localhost:4000/graphql
and interact with the playground. For example:{ hello }
-
Check the output. For the example above, the output should be:
{ "data": { "hello": "Hello world" } }
To get started with the Data Sync framework, see the sample application. In this app, you can explore a more complex schema.
Before proceeding, make sure you have an understanding of the following GraphQL concepts:
-
Schema design
-
Resolvers
-
Subscriptions