Registry / api / graphql-compose-relay

graphql-compose-relay

JSON →
library5.0.3jsnpmunverified

Plugin for graphql-compose that wraps GraphQL types with Relay-specific logic, such as the Node interface and global ID handling. Current stable version is 5.0.3, released on 2019-02-14. It provides composeWithRelay() which automatically adds Node interface, globalId field, clientMutationId to mutations, and a node field on the root query for resolving by global ID. Requires graphql-compose ^7.0.4 and graphql. Release cadence is low; last release was in 2019. Compared to manual Relay schema construction, it automatically handles globally unique IDs and Node resolving, reducing boilerplate.

npm install graphql-compose-relay
INSTALL
IMPORT
SIG · GRAPHQL-COMPOSE-RE
G
graphql-compose-relay
apijavascriptv5.0.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

composeWithRelay
import composeWithRelay from 'graphql-compose-relay'
const composeWithRelay = require('graphql-compose-relay')
Default export; CJS require works but ESM is preferred.

Shows how to apply composeWithRelay to an ObjectTypeComposer, including required recordIdFn and findById resolver setup, and schema construction.

import composeWithRelay from 'graphql-compose-relay'; import { ObjectTypeComposer } from 'graphql-compose'; import { GraphQLObjectType, GraphQLSchema, GraphQLString } from 'graphql'; // Define a simple ObjectTypeComposer (simulating from a user type) const UserTC = ObjectTypeComposer.createTemp({ name: 'User', fields: { _id: 'String', name: 'String', }, }); // Set a recordIdFn to extract ID from object UserTC.setRecordIdFn(source => source._id); // Provide a findById resolver for Node resolution const userData = []; UserTC.addResolver({ name: 'findById', type: UserTC, args: { _id: 'String!' }, resolve: async ({ args }) => userData.find(u => u._id === args._id) || null, }); // Now compose with Relay: adds Node interface, globalId, etc. composeWithRelay(UserTC); // Build schema and use it const schema = new GraphQLSchema({ query: new GraphQLObjectType({ name: 'Query', fields: { node: UserTC.getResolver('node').getFieldConfig(), }, }), });
Debug
Known issues
gotchacomposeWithRelay requires the ObjectTypeComposer to have a recordIdFn and findById resolver; otherwise it throws an error.
fix
Ensure UserTC has setRecordIdFn and addResolver for 'findById' before calling composeWithRelay.
affects: >=5.0.0
gotchaThe module does not auto-create findById resolver; you must define it yourself.
fix
Add a resolver named 'findById' to the ObjectTypeComposer before composing.
affects: *
deprecatedgraphql-compose v7 may have breaking changes; check compatibility with graphql-compose-relay peer dependency.
fix
Use graphql-compose@^7.0.4 as specified in peerDependencies.
affects: >=7.0.0
Errors
Common errors & fixes
composeWithRelay does not have recordIdFn defined
The ObjectTypeComposer passed to composeWithRelay lacks a recordIdFn.
fix
Call UserTC.setRecordIdFn(source => source.id) before composeWithRelay.
Cannot find resolver 'findById' in composeWithRelay
The ObjectTypeComposer does not have a resolver named 'findById'.
fix
Add a resolver with name 'findById' to UserTC using addResolver.
Upgrade
Version history
5.0.3latest on npm
Audit
Dependencies
graphql-composerequiredpeer dependency required for graphql-compose-relay to operate
graphqlrequiredpeer dependency required for GraphQL types and schema
Agent activity
47 hits · last 30 days
node
42
OpenAI (training)
1
Resources
graphql-compose-relay — npm install graphql-compose-relay · libregistry