0.2.1 • Published 3 years ago
graphql-transformer v0.2.1
graphql-transformer
A tool to transform GraphQL schemas via simple functions
How to use
npm install --save graphql-transformer
Basic usage:
const transformedSchema = transformSchema(originalSchema, {
transformField(field: GraphQLNamedFieldConfig<any, any>, context) {
// Rename a field in a type
if (context.oldOuterType.name == 'MyType') {
return {
...field,
name: field.name + 'ButCooler'
}
}
return field;
},
transformObjectType(type: GraphQLObjectTypeConfig<any, any>) {
if (type.name == 'MyType') {
return {
...type,
name: 'MyCoolType'
};
}
return type;
},
transformFields(fields: GraphQLFieldConfigMap<any, any>, context) {
// You can even copy types on the fly and transform the copies
const type2 = context.copyType(context.oldOuterType, {
transformObjectType(typeConfig: GraphQLObjectTypeConfig<any, any>) {
return {
...typeConfig,
name: typeConfig.name + '2'
};
}
});
// This just adds a reflexive field "self" to all types, but its type does not have
// the "self" field (because it is a copy from the original type, see above)
// it also won't have the "cool" rename applied because the top-level transformers are not applied
return {
...fields,
self: {
type: type2,
resolve: (source: any) => source
}
}
}
});
This test case demonstrates that and how it works.
Contributing
After cloning the repository, run
npm install
npm start
To run the test suite, run
npm test
To debug the tests in WebStorm, right-click on graphql-transformer-test.js
and choose Debug.
0.3.1
3 years ago
0.3.0
3 years ago
0.3.0-alpha.1
3 years ago
0.2.1
5 years ago
0.2.0
6 years ago
0.2.0-rc.1
6 years ago
0.1.6
6 years ago
0.1.5
6 years ago
0.1.5-rc.1
6 years ago
0.1.5-rc
6 years ago
0.1.4-gql12
6 years ago
0.1.4
6 years ago
0.1.3
7 years ago
0.1.2
7 years ago
0.1.1
7 years ago
0.1.0
7 years ago