feat: use object notation for schema

parent 7a8ae867
Pipeline #60333767 passed with stages
in 3 minutes and 38 seconds
......@@ -1300,6 +1300,15 @@
"integrity": "sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ==",
"dev": true
},
"axios": {
"version": "0.18.0",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.18.0.tgz",
"integrity": "sha1-MtU+SFHv3AoRmTts0AB4nXDAUQI=",
"requires": {
"follow-redirects": "^1.3.0",
"is-buffer": "^1.1.5"
}
},
"babel-jest": {
"version": "24.8.0",
"resolved": "https://registry.npmjs.org/babel-jest/-/babel-jest-24.8.0.tgz",
......@@ -3464,6 +3473,29 @@
"integrity": "sha1-UhTXU3pNBqSjAcDMJi/rhBiAAuc=",
"dev": true
},
"follow-redirects": {
"version": "1.7.0",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.7.0.tgz",
"integrity": "sha512-m/pZQy4Gj287eNy94nivy5wchN3Kp+Q5WgUPNy5lJSZ3sgkVKSYV/ZChMAQVIgx1SqfZ2zBZtPA2YlXIWxxJOQ==",
"requires": {
"debug": "^3.2.6"
},
"dependencies": {
"debug": {
"version": "3.2.6",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz",
"integrity": "sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==",
"requires": {
"ms": "^2.1.1"
}
},
"ms": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz",
"integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg=="
}
}
},
"for-in": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/for-in/-/for-in-1.0.2.tgz",
......@@ -4752,8 +4784,7 @@
"is-buffer": {
"version": "1.1.6",
"resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz",
"integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==",
"dev": true
"integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w=="
},
"is-callable": {
"version": "1.1.4",
......
......@@ -38,6 +38,7 @@
}
},
"dependencies": {
"axios": "^0.18.0",
"dotenv": "^8.0.0",
"express": "^4.16.4",
"express-graphql": "^0.8.0",
......@@ -59,4 +60,4 @@
"webpack": "^4.30.0",
"webpack-cli": "^3.3.2"
}
}
\ No newline at end of file
}
const express = require('express')
const graphqlHTTP = require('express-graphql')
const {
buildSchema,
GraphQLObjectType,
GraphQLSchema,
GraphQLInt,
GraphQLString
} = require('graphql')
const port = process.env.PORT || 3000
const app = express()
// Resolver
const hello = () => 'Hello world!'
// Schema
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'Query',
description: 'Possible queries',
fields: {
hello: {
type: GraphQLString,
resolve: hello
}
}
})
})
app.use(
'/graphql',
graphqlHTTP({
schema: schema,
graphiql: !process.env.TESTING
})
)
app.get('/', (req, res) => {
res.status(200).send('Hello World!')
})
......
const request = require('supertest')
const express = require('express')
const axios = require('axios')
const app = require('./server')
test('server is online', () => {
return request(app)
request(app)
.get('/')
.then(response => {
expect(response.statusCode).toBe(200)
})
})
test('hello world from graphql', async done => {
const expected = { data: { hello: 'Hello world!' } }
request(app)
.post('/graphql')
.send({ query: '{hello}' })
.then(response => {
expect(response.body).toEqual(expected)
done()
})
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment