Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

graphql-lazy-executor

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-lazy-executor

This executor pre validate and parse the query and returns a function to execute it.

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

GraphQL Lazy Executor

This executor pre validate and parse the query and returns a function which once executed, it returns a RxJS Observable with the result. Useful in high performance scenarios, once the query can be pre validated and parsed, and postpone the execution.

Api

	lazyExecutor(
		schema: GraphQLSchema, 
		requestString: string,
		customValidators?: GraphQLValidator | Array<GraphQLValidator>
		customExecutor?: function(/* args like http://graphql.org/graphql-js/execution/#execute*/): MaybePromise<ExecutionResult>;

Sample

	const {
	    GraphQLSchema,
	    GraphQLObjectType,
	    GraphQLString,
	    GraphQLInt
	} = require('graphql');

	const lazyExecutor = require('graphql-lazy-executor');

	const schema = new GraphQLSchema({
	    query: new GraphQLObjectType({
	        name: 'Query',
	        fields: {
	            name: {
	                type: GraphQLString,
	                args: {
	                    age: {
	                        type: GraphQLInt
	                    }
	                },
	                resolve: (root, {
	                    age
	                }, context, info) => {
	                    callback(root, context);

	                    return age ? `${root.name} - ${age}` : root.name;
	                }
	            },
	            dog: {
	                type: GraphQLString,
	                args: {
	                    age: {
	                        type: GraphQLInt
	                    }
	                },
	                resolve: (root, {
	                    age
	                }, context, info) => {
	                    return age ? `${root.dog} - ${age}` : root.dog;
	                }
	            }
	        }
	    }),
	});

	const nameDogQuery = lazyExecutor({
		schema, 
		source: `{name, dog}`
	});

    nameDogQuery({
			contextValue: {
				contextValue: 'contextValue'
			},
			rootValue: {
				name: 'Rohde',
				dog: 'Heron'
			},
			variableValues: {
				variableValues: 'variableValues'
			}
		})
        .then(console.log);

        // will print
        {
        	data: {
                name: 'Rohde',
                dog: 'Heron'
            }
        }

FAQs

Package last updated on 27 May 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc