This repository has been archived by the owner on Dec 17, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(*): Remove express wrapper, change default package export to…
… express route handler Removed the express wrapper around the package. Replaced the main export of the package with the configured express-graphql instance so that this package can be installed into othr connect-based packages without enforcing the use of express, or the authentication methods previously used. BREAKING CHANGE: Removed express boilerplate. Package now only exposes GraphQL route handler.
- Loading branch information
Simon Wears
committed
Mar 26, 2017
1 parent
03c2abc
commit 960aa73
Showing
12 changed files
with
89 additions
and
1,220 deletions.
There are no files selected for viewing
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
This file was deleted.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
const graphqlHTTP = require('express-graphql'); | ||
const graphql = require('graphql'); | ||
const GraphQLSchema = graphql.GraphQLSchema; | ||
const UserType = require('data-types/user'); | ||
const createLoader = require('helpers/healthgraph-loader'); | ||
const createStrengthItem = require('mutations/strength-training/create-item'); | ||
const deleteStrengthItem = require('mutations/strength-training/delete-item'); | ||
const editStrengthItem = require('mutations/strength-training/edit-item'); | ||
|
||
const DEFAULTS = { | ||
getAccessToken () { }, | ||
graphiql: false | ||
}; | ||
|
||
/** | ||
* | ||
* @param {object} options - Configuration object | ||
* @param {boolean} [options.graphiql=false] - Enable graphiql interface | ||
* @param {function} options.getAccessToken - Function to get the access token to be used for the request to the Healthgraph | ||
* @returns {*} | ||
*/ | ||
module.exports = function (options = {}) { | ||
|
||
const opts = Object.assign(DEFAULTS, options); | ||
|
||
return graphqlHTTP(req => { | ||
|
||
const access_token = opts.getAccessToken(req); | ||
const healthGraphLoader = createLoader(access_token); | ||
|
||
return { | ||
context: { | ||
access_token, | ||
healthGraphLoader | ||
}, | ||
graphiql: opts.graphiql, | ||
schema: new GraphQLSchema({ | ||
query: UserType, | ||
mutation: new graphql.GraphQLObjectType({ | ||
name: 'healthgraph', | ||
fields: { | ||
create_strength_activity: createStrengthItem, | ||
delete_strength_activity: deleteStrengthItem, | ||
edit_strength_activity: editStrengthItem | ||
} | ||
}) | ||
}) | ||
} | ||
}); | ||
|
||
}; |
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.