Registry / devops / graphql-sock

graphql-sock

JSON →
library1.0.1jsnpmunverified

GraphQL SOCK converts SDL files that use semantic nullability (via @semanticNonNull directive or GraphQLSemanticNonNull wrapper) into traditional SDL for legacy tooling. Version 1.0.1 is the current stable release. It supports two modes: 'semantic-to-nullable' strips semantic non-null markers, while 'semantic-to-strict' replaces them with strict non-null. The library works as a CLI tool or programmatic API. Requires graphql 15.x, 16.x, or 17.x as a peer dependency. Differentiates from similar tools by supporting both the directive and the experimental asterisk syntax, with fine-grained level control for nested types.

npm install graphql-sock
INSTALL
IMPORT
SIG · GRAPHQL-SOCK
G
graphql-sock
devopsjavascriptv1.0.1
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.

default
import { sock } from 'graphql-sock'
const sock = require('graphql-sock')
Package is ESM-only; CommonJS require will fail.
sock
import { sock } from 'graphql-sock'
import sock from 'graphql-sock'
sock is a named export, not a default export.
TypeScript type
import type { SockOptions } from 'graphql-sock'
import { SockOptions } from 'graphql-sock'
Use type-only import for type safety and to avoid bundling issues.

Converts a GraphQL schema with semantic nullability to strict non-null markers using the programmatic API.

import { sock } from 'graphql-sock'; import { buildSchema, printSchema } from 'graphql'; const sdl = ` type Query { user: User @semanticNonNull users: [User] @semanticNonNull(levels: [0, 1]) } type User { id: ID! name: String } `; const schema = buildSchema(sdl); const newSdl = sock(schema, { mode: 'semantic-to-strict' }); console.log(printSchema(newSdl)); // Output: user is now User! and users is [User!]!
Debug
Known issues
breakingESM-only package; CommonJS require will throw ERR_REQUIRE_ESM.
fix
Use import syntax or switch to dynamic import().
affects: >=1.0.0
gotchaThe 'graphql' peer dependency must be 15.x, 16.x, or 17.x. Using 14.x or 18.x may cause runtime errors.
fix
Install a compatible version of graphql: npm install graphql@^16.0.0
affects: >=1.0.0
deprecatedThe @semanticNonNull directive is a temporary placeholder and may be removed in future spec versions.
fix
Migrate to the GraphQLSemanticNonNull wrapper type when available in your GraphQL.js version.
affects: >=1.0.0
gotchaInput SDL with asterisk syntax requires a patched version of graphql (graphql@canary-pr-4192) for proper parsing.
fix
Install graphql@canary-pr-4192 or convert asterisk syntax to @semanticNonNull directive before using sock.
affects: >=1.0.0
gotchaThe function returns a GraphQLSchema object, not SDL string. To get SDL, use printSchema from graphql.
fix
Use printSchema(result) from the 'graphql' package to obtain the SDL string.
affects: >=1.0.0
Errors
Common errors & fixes
ERR_REQUIRE_ESM
Using require() to load an ES module.
fix
Replace require with import or use dynamic import().
Cannot find module 'graphql'
Missing graphql peer dependency.
fix
Run npm install graphql@^16.0.0
TypeError: Cannot read properties of undefined (reading 'astNode')
Using a graphql version outside supported range (15.x, 16.x, 17.x).
fix
Check GraphQL version; ensure it's 15, 16, or 17.
Syntax Error: Expected Name, found '*'
Asterisk syntax for semantic nullability not supported by installed graphql version.
fix
Install graphql@canary-pr-4192 or replace * with @semanticNonNull directive.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
10 hits · last 30 days
node
10
Resources
graphql-sock — npm install graphql-sock · libregistry