Package Exports
- graphile-utils
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (graphile-utils) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
graphile-utils
This package contains helpers for building plugins for GraphQL schemas utilising Graphile Engine, such as the one produced by PostGraphile.
Documentation is currently available here.
PRs to improve documentation are always welcome!
gql
Similar to the default export from graphql-tag, this export can be used to
form tagged template literals that are useful when building schema
extensions. gql in graphile-utils differs from graphql-tag in a number
of ways, most notably: it can use interpolation to generate dynamically named
fields and types, and it can embed raw values using the embed helper.
embed
Used to wrap a value to be included in a gql AST, e.g. for use in GraphQL
directives.
makeExtendPluginSchema
Enables you to add additonal types or extend existing types within your Graphile Engine GraphQL schema.
const {
makeExtendSchemaPlugin,
gql,
} = require('graphile-utils');
const MySchemaExtensionPlugin =
makeExtendSchemaPlugin(
build => ({
typeDefs: gql`...`,
resolvers: ...
})
);
module.exports = MySchemaExtensionPlugin;e.g.:
makeExtendSchemaPlugin(build => ({
typeDefs: gql`
type Random {
float: Float!
number(min: Int!, max: Int!): Int!
}
extend type Query {
random: Random
}
`,
resolvers: {
Query: {
random() {
return {};
},
},
Random: {
float() {
return Math.random();
},
number(_parent, { min, max }) {
return min + Math.floor(Math.random() * (max - min + 1));
},
},
},
}));makeAddInflectorsPlugin
If you don't like the default naming conventions that come with a Graphile Engine GraphQL schema then it's easy for you to override them using the inflector.
For example, if you want '*Patch' types to instead be called '*ChangeSet' you could make a plugin such as this one:
const { makeAddInflectorsPlugin } = require('graphile-utils');
module.exports = makeAddInflectorsPlugin({
patchType(typeName: string) {
return this.upperCamelCase(`${typeName}-change-set`);
},
});The default Graphile Engine inflectors (pluralize, singularize,
upperCamelCase, camelCase and constantCase) can be found
here.
The additional inflectors used in PostGraphile can be found here.