Last active
October 2, 2017 01:11
-
-
Save voodooattack/c4f7a261ea189ffb1894e9cb5e018587 to your computer and use it in GitHub Desktop.
Revisions
-
voodooattack revised this gist
Oct 2, 2017 . 1 changed file with 3 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 @@ -21,7 +21,9 @@ Meteor.startup(() => { // My own extension to Vulcan.js. // It's really useful when you have access to the ApolloClient inside resolvers. // This makes it possible for resolvers to make their own queries. getRenderContext() { return renderContext; }, // Copy over the userID. userId: req.loginContext ? req.loginContext.userId : undefined }, GraphQLSchema.context); // go over context and add Dataloader to each collection Collections.forEach(collection => { -
voodooattack revised this gist
Sep 25, 2017 . 1 changed file with 1 addition 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 @@ -16,7 +16,7 @@ Meteor.startup(() => { typeDefs: GraphQLSchema.finalSchema, resolvers: GraphQLSchema.resolvers, }); withRenderContextEnvironment(function (renderContext, req, res, next) { const context = deepmerge({ // My own extension to Vulcan.js. // It's really useful when you have access to the ApolloClient inside resolvers. -
voodooattack revised this gist
Sep 24, 2017 . 1 changed file with 2 additions and 0 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 @@ -3,3 +3,5 @@ To make a GraphQL query on a Vulcan.js server, your server has to connect to itself via a new HTTP connection every time it receives a request. This package makes it so that Vulcan’s GraphQL queries never leave the process. All GraphQL requests are processed with no overhead. > See also: [webtoken-session](https://gist.github.com/voodooattack/7a02881b0c762630160424f742b6f780) -
voodooattack revised this gist
Sep 23, 2017 . 3 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. -
voodooattack created this gist
Sep 23, 2017 .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,5 @@ # Internal GraphQL for Vulcan.js To make a GraphQL query on a Vulcan.js server, your server has to connect to itself via a new HTTP connection every time it receives a request. This package makes it so that Vulcan’s GraphQL queries never leave the process. All GraphQL requests are processed with no overhead. 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,39 @@ import { withRenderContextEnvironment, GraphQLSchema, Collections } from 'meteor/vulcan:lib'; import { makeExecutableSchema } from 'graphql-tools'; import { graphql, print } from 'graphql'; import DataLoader from 'dataloader'; import deepmerge from 'deepmerge'; async function findByIds(collection, ids, context) { // get documents const documents = await collection.find({ _id: { $in: ids } }).fetch(); // order documents in the same order as the ids passed as argument return ids.map(id => _.findWhere(documents, {_id: id})); } Meteor.startup(() => { const schema = makeExecutableSchema({ typeDefs: GraphQLSchema.finalSchema, resolvers: GraphQLSchema.resolvers, }); withRenderContextEnvironment(async function (renderContext, req, res, next) { const context = deepmerge({ // My own extension to Vulcan.js. // It's really useful when you have access to the ApolloClient inside resolvers. // This makes it possible for resolvers to make their own queries. getRenderContext() { return renderContext; } }, GraphQLSchema.context); // go over context and add Dataloader to each collection Collections.forEach(collection => { context[collection.options.collectionName].loader = new DataLoader(ids => findByIds(collection, ids, context), { cache: true }); }); renderContext.apolloClient.networkInterface = { query: (request) => { return graphql(schema, print(request.query), {}, context, request.variables, request.debugName); } }; next(); }, { order: 23, name: 'internal-graphql-middleware' }); }); 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,20 @@ Package.describe({ name: 'internal-graphql', version: '0.0.1', // Brief, one-line summary of the package. summary: 'Prevent extraneous HTTP connections created by Vulcan to itself.', // URL to the Git repository containing the source code for this package. git: '', // By default, Meteor will default to using README.md for documentation. // To avoid submitting documentation, set this field to null. documentation: 'README.md' }); Package.onUse(function(api) { api.versionsFrom('1.5.1'); api.use([ 'ecmascript', 'vulcan:lib' ]); api.mainModule('internal-graphql.js', ['server']); });