prismagraphql/graphql-transform-schema

Name: graphql-transform-schema

Owner: Prisma

Description: Transform, filter & alias resolvers of a GraphQL schema

Created: 2017-09-03 14:13:35.0

Updated: 2018-05-02 14:55:36.0

Pushed: 2018-05-21 16:44:00.0

Homepage: https://example-rakllksfme.now.sh/graphiql

Size: 66

Language: TypeScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

graphql-transform-schema Build Status npm version Greenkeeper badge

Transform, filter & alias resolvers of a GraphQL schema

Install
 add graphql-transform-schema
Usage

By default transformSchema passes through all queries/mutations. (Open Demo)

rt { transformSchema } from 'graphql-transform-schema'

eeded for remote schemas
rt { createApolloFetch } from 'apollo-fetch'
rt { makeRemoteExecutableSchema } from 'graphql-tools'

t schema = await makeRemoteExecutableSchema(createApolloFetch({
i: 'https://api.graph.cool/simple/v1/swapi',


ide every query/mutation except the `Starship` and `allStarships` query
t transformedSchema = transformSchema(schema, {
': false,
arship: true,
lStarships: true,


t transformedSchema = transformSchema(schema, {
ery: {
'*': false,
Starship: true,
allStarships: true,

tation: {


arship: {
'*': false,
id: true,


API
rface Rules {
ieldName: string]: boolean | Function


tion transformSchema(schema: GraphQLSchema, rules: Rules): GraphQLSchema
Examples
Remove all createX and deleteX mutations
t transformedSchema = transformSchema(schema, {
tation: {
'create*': false,
'delete*': false


Overwrite resolved data
t typeDefs = `
pe Query {
hello: String!


pe Mutation {
alexaHello(name: String!): String!


t resolvers = {
ery: {
hello: () => 'Hello world',

tation: {
alexaHello: (_, { name }) => `Alexa: Hello world, ${name}`,


t schema = makeExecutableSchema({ typeDefs, resolvers })

t transformedSchema = transformSchema(schema, {
exaHello: ({ args, resolve }) => resolve(args).replace('Bob', 'Alice'),

Overwrite arguments
t typeDefs = `
pe Query {
hello: String!


pe Mutation {
alexaHello(name: String!): String!


t resolvers = {
ery: {
hello: () => 'Hello world',

tation: {
alexaHello: (_, { name }) => `Alexa: Hello world, ${name}`,


t schema = makeExecutableSchema({ typeDefs, resolvers })

t transformedSchema = transformSchema(schema, {
exaHello: ({ args, resolve }) => resolve({ name: 'John' }),

Next steps
Help & Community Slack Status

Join our Slack community if you run into issues or have questions. We love talking to you!


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.