Created
April 21, 2021 20:42
-
-
Save smpnjn/4c3a17fd51b53ac58442afc554da9a66 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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