smallorange-graphql-rxjs
v1.0.4
Published
Rxjs wrapper for Graphql
Downloads
6
Readme
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);