Skip to content

Commit

Permalink
#35 add graphql node.
Browse files Browse the repository at this point in the history
  • Loading branch information
tanakaryo committed Jun 24, 2024
1 parent cb4a9db commit d1b5016
Show file tree
Hide file tree
Showing 946 changed files with 117,526 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
const express = require('express');
const express_gql = require('express-graphql').graphqlHTTP;
const { buildSchema } = require('graphql');

const appServer = express();

var schema = buildSchema(`
type Query {
person(name: String!): BusinessPerson
department(dept: String!): [BusinessPerson]
},
type BusinessPerson {
name: String,
age: Int,
country: String,
dept: String
}
`);

var businessPersonData = [
{
name: 'David Schott',
age: 14,
country: "United States",
dept: "dept1"
},
{
name: 'Satoshi Yoshida',
age: 15,
country: "Japan",
dept: "dept1"
},
{
name: 'Jackson Lee',
age: 16,
country: "England",
dept: "dept2"
}
]

var getPerson = function(args) {
var name = args.name;
return businessPersonData.filter(person => {
return person.name == name;
})[0];
}

var getDepartment = function(args) {
if (args.dept) {
var dept = args.dept;
return businessPersonData.filter(person => {
return person.dept == dept;
});
} else {
return businessPersonData;
}
}

var root = {
person: getPerson,
department : getDepartment
};

appServer.use('/graphql', express_gql({
schema: schema,
rootValue: root,
graphiql: true
}));

appServer.listen(4000, () => console.log('GqlServer is running...'));

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d1b5016

Please sign in to comment.