Last active
February 13, 2025 09:36
-
-
Save xpepermint/7376b8c67caa926e19d2 to your computer and use it in GitHub Desktop.
Revisions
-
xpepermint revised this gist
Sep 18, 2015 . 2 changed files with 19 additions and 5 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,16 +1,17 @@ curl -XPOST -H "Content-Type:application/graphql" -d ' query RootQuery { project(id: 2) { name } projects { id name members { id name tickets { message } } } }' http://localhost:4444/graphql 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 charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,9 @@ import { GraphQLObjectType, GraphQLString, GraphQLInt, GraphQLList, GraphQLID, GraphQLNonNull } from 'graphql/type'; const TicketType = new GraphQLObjectType({ @@ -71,6 +73,17 @@ const RootType = new GraphQLObjectType({ {id: 2, name: `Project 2`} ]; } }, project: { type: ProjectType, args: { id: { type: new GraphQLNonNull(GraphQLID) } }, resolve(parent, {id}) { return {id: id, name: `Project ${id}`} } } } }); @@ -79,4 +92,4 @@ const schema = new GraphQLSchema({ query: RootType }); export default schema; -
xpepermint revised this gist
Sep 18, 2015 . 4 changed files with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes.File renamed without changes.File renamed without changes.File renamed without changes. -
xpepermint revised this gist
Sep 18, 2015 . 4 changed files with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes.File renamed without changes.File renamed without changes.File renamed without changes. -
xpepermint revised this gist
Sep 18, 2015 . 4 changed files with 175 additions and 5 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ curl -XPOST -H "Content-Type:application/graphql" -d ' query RootQuery { projects { id name members { id name tickets { id message } } } } ' http://localhost:4444/graphql 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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,3 @@ 1. Build GraphQL server using `express-graphql` package. 2. Configure `schema.js` file. 3. Query for data. 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,82 @@ import { GraphQLSchema, GraphQLObjectType, GraphQLString, GraphQLInt, GraphQLList } from 'graphql/type'; const TicketType = new GraphQLObjectType({ name: 'TicketType', fields: { id: { type: GraphQLString }, message: { type: GraphQLString } } }); const MemberType = new GraphQLObjectType({ name: 'MemberType', fields: { id: { type: GraphQLInt }, name: { type: GraphQLString }, tickets: { type: new GraphQLList(TicketType), resolve(member) { return [ {id: 1, message: `Member: ${member.id}, Ticket: 1`}, {id: 2, message: `Member: ${member.id}, Ticket: 2`} ]; } } } }); const ProjectType = new GraphQLObjectType({ name: 'ProjectType', fields: { id: { type: GraphQLInt }, name: { type: GraphQLString }, members: { type: new GraphQLList(MemberType), resolve(project) { return [ {id: 1, name: `Project: ${project.id}, Member: 1`}, {id: 2, name: `Project: ${project.id}, Member: 2`} ]; } } } }); const RootType = new GraphQLObjectType({ name: 'RootType', fields: { projects: { type: new GraphQLList(ProjectType), resolve() { return [ {id: 1, name: `Project 1`}, {id: 2, name: `Project 2`} ]; } } } }); const schema = new GraphQLSchema({ query: RootType }); export default schema; 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,74 @@ { "data": { "projects": [ { "id": 1, "name": "Project 1", "members": [ { "id": 1, "name": "Project: 1, Member: 1", "tickets": [ { "id": "1", "message": "Member: 1, Ticket: 1" }, { "id": "2", "message": "Member: 1, Ticket: 2" } ] }, { "id": 2, "name": "Project: 1, Member: 2", "tickets": [ { "id": "1", "message": "Member: 2, Ticket: 1" }, { "id": "2", "message": "Member: 2, Ticket: 2" } ] } ] }, { "id": 2, "name": "Project 2", "members": [ { "id": 1, "name": "Project: 2, Member: 1", "tickets": [ { "id": "1", "message": "Member: 1, Ticket: 1" }, { "id": "2", "message": "Member: 1, Ticket: 2" } ] }, { "id": 2, "name": "Project: 2, Member: 2", "tickets": [ { "id": "1", "message": "Member: 2, Ticket: 1" }, { "id": "2", "message": "Member: 2, Ticket: 2" } ] } ] } ] } } -
xpepermint revised this gist
Sep 18, 2015 . 1 changed file with 5 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1 +1,5 @@ // GraphQL schema example ```js console.log(111) ``` -
xpepermint created this gist
Sep 18, 2015 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ // GraphQL schema example