Registry / serialization / graphql-s2s

graphql-s2s

JSON →
library0.22.0jsnpmunverified

GraphQL S2S (Schema-to-Schema) is a transpiler that extends standard GraphQL SDL with type inheritance, generic types, metadata decoration, and query deconstruction/transformation/rebuilding. Version 0.22.0 is the latest stable release. It allows developers to define reusable schema patterns before transpiling to standard GraphQL syntax for graphql-js and Apollo Server. Key differentiators: supports multiple inheritance, generic type parameters (like Paged<T>), schema-level metadata annotations, and programmatic query manipulation. Unlike graphql-modules or type-graphql, graphql-s2s works purely at the SDL string level without requiring class definitions or decorators.

npm install graphql-s2s
INSTALL
IMPORT
SIG · GRAPHQL-S2S
G
graphql-s2s
serializationjavascriptv0.22.0
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.

transpileSchema
import { transpileSchema } from 'graphql-s2s'
const transpileSchema = require('graphql-s2s').graphqls2s.transpileSchema
ESM named export since v0.18.0; CommonJS users need to destructure from .graphqls2s.
graphqls2s
import { graphqls2s } from 'graphql-s2s'
const graphqls2s = require('graphql-s2s')
Default export is the graphqls2s object (CommonJS compatibility); ESM prefers named exports.
deconstructQuery
import { deconstructQuery } from 'graphql-s2s'
For query AST manipulation; available since v0.12.0.

Shows transpilation of an enriched schema with inheritance to standard GraphQL.

import { transpileSchema } from 'graphql-s2s'; import { makeExecutableSchema } from '@graphql-tools/schema'; const enrichedSchema = ` type Node { id: ID! } type Person inherits Node { firstname: String lastname: String } type Query { people: [Person] } `; const schema = makeExecutableSchema({ typeDefs: [transpileSchema(enrichedSchema)], resolvers: { Query: { people: () => [{ id: '1', firstname: 'John', lastname: 'Doe' }] } } }); // schema is now ready for graphql execution
Debug
Known issues
breakingIn v0.16.0, the package switched from default export to named exports. require('graphql-s2s') no longer returns a function.
fix
Use destructuring: const { transpileSchema } = require('graphql-s2s').graphqls2s (old) or import { transpileSchema } from 'graphql-s2s' (new).
affects: >=0.16.0
deprecatedThe .graphqls2s property for CommonJS require access is deprecated and may be removed in future versions.
fix
Use named ESM imports or await import('graphql-s2s').
affects: >=0.16.0 <1.0.0
gotchaInheritance does not merge fields from parent types automatically; you must manually add fields to the child. The 'inherits' keyword only copies fields at transpile time, not during schema execution.
fix
Always declare all fields in the child type, even if inherited.
affects: >=0.1.0
gotchaGeneric types like Paged<T> must be instantiated with a concrete type; generics without instantiation will cause parse errors.
fix
Always use Paged<Question> not just Paged.
affects: >=0.1.0
gotchaThe transpiled schema may contain duplicate type definitions if multiple inheritance chains have overlapping fields; transpileSchema does not deduplicate.
fix
Manually deduplicate or use interface merging patterns.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: Cannot destructure property 'transpileSchema' of 'require(...).graphqls2s' as it is undefined
Using old import pattern with newer version that exports directly.
fix
Use import { transpileSchema } from 'graphql-s2s' (ESM) or const { transpileSchema } = require('graphql-s2s').graphqls2s only for versions <0.16.0; for >=0.16.0 use const { graphqls2s } = require('graphql-s2s'); const { transpileSchema } = graphqls2s.
Error: Cannot find module 'graphql-s2s'
Package not installed or incorrect path.
fix
Run 'npm install graphql-s2s' and ensure node_modules contains it.
GraphQLError: Syntax Error: Expected Name, found <EOF>
Generic type used without instantiation (e.g., using Paged in schema without angle brackets).
fix
Instantiate the generic: type Paged<T> { data: [T] } then type Query { items: Paged<Item> }.
TypeError: graphqls2s is not a function
Calling require('graphql-s2s') directly as a function in older versions.
fix
Use require('graphql-s2s').graphqls2s.transpileSchema(...) or import the named export.
Upgrade
Version history
0.22.0latest on npm
Audit
Dependencies
graphqlrequiredpeer dependency for typeDefs and schema construction
Agent activity
4 hits · last 30 days
node
4
Resources
graphql-s2s — npm install graphql-s2s · libregistry