Skip to content

matusmarcin/graphql-hello-world

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

GraphQL Hello World

This is a very simple example based on Getting Started With GraphQL.js.

The whole thing is just:

npm init
npm install graphql --save

Create a server.js:

var { graphql, buildSchema } = require('graphql');

// Construct a schema, using GraphQL schema language
var schema = buildSchema(`
  type Query {
    hello: String
  }
`);

// The root provides a resolver function for each API endpoint
var root = {
  hello: () => {
    return 'Hello world!';
  },
};

// Run the GraphQL query '{ hello }' and print out the response
graphql(schema, '{ hello }', root).then((response) => {
  console.log(response);
});

And now you can:

node server.js

Which should output:

{ data: { hello: 'Hello world!' } }

🎉

About

Simple GraphQL Hello World example.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published