Last active
August 29, 2015 14:25
Revisions
-
frikille revised this gist
Jul 19, 2015 . 1 changed file with 3 additions and 3 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 @@ -9,7 +9,7 @@ import PostType from './PostType.js'; import User from '../models/User.js'; let QueryType = new GraphQLObjectType({ name: 'DataQuery', fields: () => ({ post: { type: PostType, @@ -38,7 +38,7 @@ let QueryType = new GraphQLObjectType({ }); let SessionQueryType = new GraphQLObjectType({ name: 'Query', fields: () => ({ data: { type: QueryType, @@ -77,6 +77,6 @@ export default { let loggedInUserId = (request.session) ? request.session.passport.user : null; return graphql(schema, query, 'Query', {loggedInUserId}); } }; -
frikille revised this gist
Jul 19, 2015 . 1 changed file with 7 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,4 +1,10 @@ import { graphql, GraphQLObjectType, GraphQLInt, GraphQLString, GraphQLSchema } from 'graphql'; import PostType from './PostType.js'; import User from '../models/User.js'; -
frikille revised this gist
Jul 19, 2015 . 1 changed file with 62 additions and 2 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,5 +1,65 @@ import { graphql } from 'graphql'; import PostType from './PostType.js'; import User from '../models/User.js'; let QueryType = new GraphQLObjectType({ name: 'Query', fields: () => ({ post: { type: PostType, args: { id: { name: 'id', type: GraphQLInt }, journal: { name: 'journal', description: 'The journal slug', type: GraphQLString }, post: { name: 'post', description: 'The post slug', type: GraphQLString } }, resolve: (user, {id, journal, post}) => { return Post.authorise(user, {id, journal, post}) .then(post => post && post.toJSON()); } } }) }); let SessionQueryType = new GraphQLObjectType({ name: 'SessionQuery', fields: () => ({ data: { type: QueryType, args: { id: { name: 'loggedInUserId', type: GraphQLInt } }, resolve: (root, {loggedInUserId}) => { return User.forge({id: loggedInUserId}) .fetch() .then(user => { if (user) { return user.toJSON(); } else { return {}; } }); } } }) }); let schema = new GraphQLSchema({ query: SessionQueryType }); export default { query(body, request) { @@ -11,6 +71,6 @@ export default { let loggedInUserId = (request.session) ? request.session.passport.user : null; return graphql(schema, query, 'SessionQuery', {loggedInUserId}); } }; -
frikille created this gist
Jul 19, 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,16 @@ import { graphql } from 'graphql'; import schema from '../graphql/schema.js'; export default { query(body, request) { let query = `query Query($loggedInUserId: Int) { data(id: $loggedInUserId) { ${body} } }`; let loggedInUserId = (request.session) ? request.session.passport.user : null; return graphql(schema, query, 'Query', {loggedInUserId}); } };