-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
50 lines (44 loc) · 1.24 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const express = require('express');
const app = express();
app.use(express.json());
const port = process.env.PORT || 3000;
app.listen(port, () => console.log(`Server running on port ${port}`));
const { buildQuery } = require('graphql-query-builder');
const { graphql } = require('graphql');
const { GraphQLObjectType, GraphQLString, GraphQLSchema } = require('graphql');
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'Query',
fields: {
user: {
type: GraphQLString,
args: {
id: { type: GraphQLString },
},
resolve: (parent, args) => {
return `{
user(id: ${args.id}) {
name
email
}
}`;
},
},
},
}),
});
app.post('/convert', (req, res) => {
const { text } = req.body;
const query = buildQuery('query', {
user: {
__args: {
id: 123,
},
name: true,
email: true,
},
});
graphql(schema, query).then(result => {
res.json({ query: result });
});
});