You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jul 11, 2025. It is now read-only.
Deprecated: This library will no longer be maintained. Use at your own risk!
Installation
npm install --save @dreamit/graphql-std-schema
TypeScript declarations are provided within the project.
Features
Works with both strings and objects
Strings can be parsed to objects (see parseStringToObject option)
Checks/Validates if input is a valid GraphQL response
At least one of data or errors field exists
data needs to be an object
errors needs to be an array
errors should not be empty is it exists
extensions should be an object if it exists
There should be no additional fields besides data, errors and
extensions (configurable)
findIssues function is exported and can be used without generating a schema
Typescript with zero additional production dependencies
Content of the library
The library exports one type and two functions.
graphQLResponseSchema: Creates a GraphQL response schema. Options can
be provided to adjust validation/checks
findIssues: Checks for issues in the response object with the given options.
Internally used but can also be used standalone to check for issues without
generating a Schema.
ValidationOptions: Interface for the Validation options.
Two options are available to configure validation behavior. See interface below.
exportinterfaceValidationOptions{/** * In a GraphQL response only the fields "data", "errors" and "extensions" are allowed. When set to true * this checks allows additional fields. According to GraphQL spec October 2021 this should not be the case. */allowAdditionalFieldsInResponse?: boolean/** * If value is a string, define if it should be parsed to an object. Otherwise an issue will be created. */parseStringToObject?: boolean}
Validate an input
To validate an input the schema can be generated with graphQLResponseSchema()
and the input can be validated with the validate function. For a quick check the findIssues function can be used
without a schema, the function will return a StandardSchemaV1.Issue[].
Example code:
// Optionally, provide options to adjust validationconstschema=graphQLResponseSchema()constvalidationResults=schema['~standard'].validate(someInput)// Quick validation without a schemaconstfoundValidationIssues=findIssues(someInput)
Contact
If you have problems, questions or issues please visit our
Issue page and open a
new issue if there are no fitting issues for your topic yet.