0.0.7 • Published 11 months ago
Last release 11 months ago
Share package GraphQL JSON GraphQL JSON is a powerful tool that helps you create GraphQL schemas using JSON. With an input schema based on the GraphQL type API, it should feel familiar to most users.
This package offers a TypeScript-typed solution for creating schemas for your GraphQL server, allowing you to take advantage of TypeScript to avoid errors. At the same time, it preserves the flexibility that GraphQL offers, enabling you to shape your schema to your liking.
The main goal of this package is to simplify the process of constructing GraphQL schemas. It helps you eliminate unnecessary clutter, making it easier to understand and modify your schemas. This way, you can reduce errors and build a reliable GraphQL API without the downsides of the GraphQL Types API or the GraphQL Schema Language.
Installation You can install graphql-json
by running one of the commands below.
# npm
npm install @gwesseling/graphql-json
# yarn
yarn add @gwesseling/graphql-json
# pnpm
pnpm install @gwesseling/graphql-json
Usage The usage of these packages is very straightforward.
import createSchema from "@gwesseling/graphql-json";
const server = new ApolloServer({
schema: createSchema(schema, options),
});
For a complete input examples, please refer to the examples folder. This folder contains a comprehensive JSON input, as well as the resulting output generated by the tool.
Schema Base type Property Description Type Required description description of your type string
No type The related GraphQL type GraphQLType No
Types Type Description GraphQLEnumType A GraphQL enum type GraphQLObjectType A GraphQL object type GraphQLScalarType A GraphQL scalar type GraphQLUnionType A GraphQL union type GraphQLInputObjectType A GraphQL input object type GraphQLInterfaceType A GraphQL interface type name Either the name of a GraphQL type inside the schema or a GraphQL type name
Named types Type Description enum A GraphQL enum type object A GraphQL object type scalar A GraphQL scalar type union A GraphQL union type input A GraphQL input object type interface A GraphQL interface type id A GraphQL id scalar type string A GraphQL string scalar type int A GraphQL integer scalar type float A GraphQL float scalar type boolean A GraphQL boolean scalar type name Either the name of a GraphQL type inside the schema or a GraphQL type name
Input types Type Description GraphQLEnumType A GraphQL enum type GraphQLScalarType A GraphQL scalar type GraphQLInputObjectType A GraphQL input object type name Either the name of a GraphQL type inside the schema or a GraphQL type name
Output types Type Description GraphQLEnumType A GraphQL enum type GraphQLObjectType A GraphQL object type GraphQLScalarType A GraphQL scalar type GraphQLUnionType A GraphQL union type GraphQLInterfaceType A GraphQL interface type name Either the name of a GraphQL type inside the schema or a GraphQL type name
Enum type Property Description Type Required values An object map with enum values (same as in GraphQL) Object
Yes
Object type Property Description Type Required interfaces Array of interfaces to implement Array
(string
or GraphQLInterface
)No fields An object map of fields Field type Yes isTypeOf A function that helps resolve the GraphQL type of the object (value: any, info?: GraphQLResolveInfo) => boolean
No
Input object type Property Description Type Required fields An object map of fields Field Yes
Union type Property Description Type Required types Types to combine as an Union type GraphQLObjectType
or string
(a GraphQL object inside the schema)Yes resolveType A function that helps resolve the GraphQL type of the object (value: TSource, context: TContext, info: GraphQLResolveInfo, abstractType: GraphQLAbstractType, ) => PromiseOrValue<string / undefined>
No
Interface type Property Description Type Required interfaces Array of interfaces to implement Array
(string
or GraphQLInterface
)No fields An object map of fields Field type Yes resolveType A function that helps resolve the GraphQL type of the object (value: TSource, context: TContext, info: GraphQLResolveInfo, abstractType: GraphQLAbstractType, ) => PromiseOrValue<string / undefined>
No
Scalar type Property Description Type Required specifiedByURL Scalar specification URL string
No serialize Function to serialize the value to JSON (outputValue: unknown) => TExternal
No parseValue Function to parse the value (inputValue: unknown) => TInternal;
No parseLiteral Function to partse the hard-coded AST (valueNode: ValueNode, variables?: Maybe<ObjMap<unknown>>) => TInternal;
No
Sub types Field type Property Description Type Required type Type of the field Output type or string
(a GraphQL type inside the schema)No* list List item type List type No* required Whenever the field is non-nullable boolean
No (default false) args Object map of arguments Argument type no resolve Resolves field data (source: TSource, args: TArgs, context: TContext, info: GraphQLResolveInfo) => TResult;
No subscribe Subscribe to field (source: TSource, args: TArgs, context: TContext, info: GraphQLResolveInfo) => TResult;
No deprecationReason Reason why field is deprecated string
No
* Either type or list is required.
Field list type Property Description Type Required type GraphQLList
typeOutput Type or string
(a GraphQL type inside the schema)Yes required Whenever the field is non-nullable boolean
No
Field argument Property Description Type Required type Type of the argument Input type or string
(a GraphQL type inside the schema)No* list List item type List type No* deprecationReason Reason why argument is deprecated string
No
* Either type or list is required.
Field argument item type Property Description Type Required type GraphQLList
typeInput type or string
(a GraphQL type inside the schema)Yes required Whenever the field is non-nullable boolean
No
Input object field type Property Description Type Required type Type of the field Input type or string
(a GraphQL type inside the schema)No* list List item type Item type No* required Whenever the field is non-nullable boolean
No defaultValue Default field value unknown
No deprecationReason Reason why argument is deprecated string
No
* Either type or list is required.
Input object field item type Property Description Type Required type GraphQLList
typeInput type or string
(a GraphQL type inside the schema)Yes required Whenever the field is non-nullable boolean
No
Options Property Description Type Required context Pre-fill the context with custom types that graphql-json can use to resolve types object
No description Schema description string
No types Schema description types Array of GraphQLNamedType
or string
No directives Schema directives Array of GraphQLDirective
No extensions Schena extension GraphQLSchemaExtensions
No astNode Schema astNode SchemaDefinitionNode
No extensionASTNodes Schema extensionASTNodes SchemaExtensionNode
No