smallorange-graphql-rxjs

1.0.4 • Public • Published

CircleCI

Small Orange GraphQL Rxjs

Rxjs wrapper to GraphQL.

Usage

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

	const graphql = require('smallorange-graphql-rxjs');
	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 ? `name - ${age}` : 'name';
	                }
	            },
	            dog: {
	                type: GraphQLString,
	                args: {
	                    age: {
	                        type: GraphQLInt
	                    }
	                },
	                resolve: (root, {
	                    age
	                }, context, info) => {
	                    return age ? `dog - ${age}` : 'dog';
	                }
	            },
	            error: {
	                type: GraphQLString,
	                args: {
	                    age: {
	                        type: GraphQLInt
	                    }
	                },
	                resolve: () => {
	                    throw new Error('error');
	                }
	            }
	        }
	    })
	});

	graphql({
	    schema,
	    requestString: `query($age: Int!){
                    name(age: $age)
                    dog(age: $age)
                }`,
        rootValue: {},
        contextValue: {},
       	variableValues: {
            age: 10
        }
	})
	.map(response => response.data) // rxjs chain
	.subscribe(nextFn, errorFn, completeFn);

Readme

Keywords

none

Package Sidebar

Install

npm i smallorange-graphql-rxjs

Weekly Downloads

0

Version

1.0.4

License

ISC

Last publish

Collaborators

  • feliperohde