Created
April 25, 2017 23:14
-
-
Save AdamZaczek/7d9e9eb9d9eb35a25878032debc945ab to your computer and use it in GitHub Desktop.
GraphQL Getting Started Code Fragment 4
This file contains 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
/* eslint no-underscore-dangle: off*/ | |
/* eslint "arrow-body-style": off */ | |
import { | |
GraphQLList, | |
GraphQLObjectType, | |
GraphQLSchema, | |
GraphQLString, | |
} from 'graphql'; | |
import USER from './models/user'; | |
import SKILL from './models/skill'; | |
import LEVEL_SKILL from './models/levelSkill'; | |
const User = new GraphQLObjectType({ | |
name: 'User', | |
description: 'Represents user', | |
fields: () => ({ | |
_id: { type: GraphQLString }, | |
firstName: { type: GraphQLString }, | |
lastName: { type: GraphQLString }, | |
role: { type: GraphQLString } | |
}) | |
}); | |
const Query = new GraphQLObjectType({ | |
name: 'ProfileSchema', | |
description: 'Root of the Profile', | |
fields: () => ({ | |
helloQuery: { | |
type: GraphQLString, | |
description: 'Our first query field!', | |
resolve: () => { | |
return 'Hello from GraphiQL'; | |
} | |
}, | |
users: { | |
type: new GraphQLList(User), | |
description: 'Netguru members', | |
resolve: () => { | |
return USER.find({}, (err, res) => { | |
return res; | |
}); | |
} | |
} | |
}) | |
}); | |
const Schema = new GraphQLSchema({ | |
query: Query | |
}); | |
export default Schema; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment