Skip to content
This repository has been archived by the owner on Dec 17, 2018. It is now read-only.

Commit

Permalink
refactor(graphql): Remove HealthGraph root node
Browse files Browse the repository at this point in the history
Removed the root healthgraph node in the graphQL schema, instead giving direct access from root to
all keys from the /user call

BREAKING CHANGE: Schema is no longer wrapped in root healthgraph key
  • Loading branch information
Simon Wears committed Mar 19, 2017
1 parent 807f185 commit 08defbe
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 21 deletions.
15 changes: 9 additions & 6 deletions src/data-types/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,30 @@ module.exports = new GraphQLObjectType({
fields: {
fitness_activities: {
description: i18n.t('GRAPHQL.USER.FITNESS_ACTIVITIES'),
resolve (data, args, req) {
return fetch(data.fitness_activities, req);
resolve (parent, args, req) {
return fetch('/user', req).then(data => fetch(data.fitness_activities, req));
},
type: FitnessActivitiesType
},
profile: {
description: i18n.t('GRAPHQL.USER.PROFILE'),
resolve (data, args, req) {
return fetch(data.profile, req);
resolve (parent, args, req) {
return fetch('/user', req).then(data => fetch(data.profile, req));
},
type: ProfileType
},
strength_training_activities: {
description: i18n.t('GRAPHQL.USER.STRENGTH_TRAINING_ACTIVITIES'),
resolve (data, args, req) {
return fetch(data.strength_training_activities, req);
resolve (parent, args, req) {
return fetch('/user', req).then(data => fetch(data.strength_training_activities, req));
},
type: StrengthTrainingActivitiesType
},
userID: {
description: i18n.t('GRAPHQL.USER.USERID'),
resolve (parent, args, req) {
return fetch('/user', req).then(data => data.userID);
},
type: GraphQLString
}
}
Expand Down
17 changes: 2 additions & 15 deletions src/routes/graphql.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,16 @@
const graphqlHTTP = require('express-graphql');
const graphql = require('graphql');
const GraphQLSchema = graphql.GraphQLSchema;
const GraphQLObjectType = graphql.GraphQLObjectType;
const fetch = require('../helpers/fetch');

const HealthGraphType = require('../data-types/user');
const UserType = require('../data-types/user');

module.exports = function (app) {

app.use('/graphql', graphqlHTTP({
graphiql: true,
schema: new GraphQLSchema({
query: new GraphQLObjectType({
name: 'HealthGraph',
fields: {
healthgraph: {
type: HealthGraphType,
resolve (parent, args, req) {
return fetch('/user', req);
}
}
}
})
query: UserType
})

}));

};

0 comments on commit 08defbe

Please sign in to comment.