Skip to content

Instantly share code, notes, and snippets.

@smpnjn
Created April 21, 2021 20:42
Show Gist options
  • Save smpnjn/4c3a17fd51b53ac58442afc554da9a66 to your computer and use it in GitHub Desktop.
Save smpnjn/4c3a17fd51b53ac58442afc554da9a66 to your computer and use it in GitHub Desktop.
import express from 'express';
import { graphqlHTTP } from 'express-graphql';
import { buildSchema } from 'graphql'
/* A schema is used to define how the data will look */
let schema = buildSchema(`
type Query {
title: String,
age: Int,
description: String
}
`);
/* A root value is used to say what will be RETURNED for each schema element */
let root = {
title: () => { return "Fjolt" },
age: () => { return 5 },
description: () => { return 'A website' }
};
/* We tie it all together with express, so a user can access the endpoint */
let app = express();
app.get('/api', graphqlHTTP({
schema: schema,
rootValue: root
}));
app.listen(4000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment