0.0.7 • Published 11 months ago

@gwesseling/graphql-json v0.0.7

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

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.

graphql-json

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

PropertyDescriptionTypeRequired
descriptiondescription of your typestringNo
typeThe related GraphQL typeGraphQLTypeNo

Types

TypeDescription
GraphQLEnumTypeA GraphQL enum type
GraphQLObjectTypeA GraphQL object type
GraphQLScalarTypeA GraphQL scalar type
GraphQLUnionTypeA GraphQL union type
GraphQLInputObjectTypeA GraphQL input object type
GraphQLInterfaceTypeA GraphQL interface type
nameEither the name of a GraphQL type inside the schema or a GraphQL type name

Named types

TypeDescription
enumA GraphQL enum type
objectA GraphQL object type
scalarA GraphQL scalar type
unionA GraphQL union type
inputA GraphQL input object type
interfaceA GraphQL interface type
idA GraphQL id scalar type
stringA GraphQL string scalar type
intA GraphQL integer scalar type
floatA GraphQL float scalar type
booleanA GraphQL boolean scalar type
nameEither the name of a GraphQL type inside the schema or a GraphQL type name

Input types

TypeDescription
GraphQLEnumTypeA GraphQL enum type
GraphQLScalarTypeA GraphQL scalar type
GraphQLInputObjectTypeA GraphQL input object type
nameEither the name of a GraphQL type inside the schema or a GraphQL type name

Output types

TypeDescription
GraphQLEnumTypeA GraphQL enum type
GraphQLObjectTypeA GraphQL object type
GraphQLScalarTypeA GraphQL scalar type
GraphQLUnionTypeA GraphQL union type
GraphQLInterfaceTypeA GraphQL interface type
nameEither the name of a GraphQL type inside the schema or a GraphQL type name

Enum type

PropertyDescriptionTypeRequired
valuesAn object map with enum values (same as in GraphQL)ObjectYes

Object type

PropertyDescriptionTypeRequired
interfacesArray of interfaces to implementArray (string or GraphQLInterface)No
fieldsAn object map of fieldsField typeYes
isTypeOfA function that helps resolve the GraphQL type of the object(value: any, info?: GraphQLResolveInfo) => booleanNo

Input object type

PropertyDescriptionTypeRequired
fieldsAn object map of fieldsFieldYes

Union type

PropertyDescriptionTypeRequired
typesTypes to combine as an Union typeGraphQLObjectType or string (a GraphQL object inside the schema)Yes
resolveTypeA function that helps resolve the GraphQL type of the object(value: TSource, context: TContext, info: GraphQLResolveInfo, abstractType: GraphQLAbstractType, ) => PromiseOrValue<string / undefined>No

Interface type

PropertyDescriptionTypeRequired
interfacesArray of interfaces to implementArray (string or GraphQLInterface)No
fieldsAn object map of fieldsField typeYes
resolveTypeA function that helps resolve the GraphQL type of the object(value: TSource, context: TContext, info: GraphQLResolveInfo, abstractType: GraphQLAbstractType, ) => PromiseOrValue<string / undefined>No

Scalar type

PropertyDescriptionTypeRequired
specifiedByURLScalar specification URLstringNo
serializeFunction to serialize the value to JSON(outputValue: unknown) => TExternalNo
parseValueFunction to parse the value(inputValue: unknown) => TInternal;No
parseLiteralFunction to partse the hard-coded AST(valueNode: ValueNode, variables?: Maybe<ObjMap<unknown>>) => TInternal;No

Sub types

Field type

PropertyDescriptionTypeRequired
typeType of the fieldOutput type or string (a GraphQL type inside the schema)No*
listList item typeList typeNo*
requiredWhenever the field is non-nullablebooleanNo (default false)
argsObject map of argumentsArgument typeno
resolveResolves field data(source: TSource, args: TArgs, context: TContext, info: GraphQLResolveInfo) => TResult;No
subscribeSubscribe to field(source: TSource, args: TArgs, context: TContext, info: GraphQLResolveInfo) => TResult;No
deprecationReasonReason why field is deprecatedstringNo

* Either type or list is required.

Field list type

PropertyDescriptionTypeRequired
typeGraphQLList typeOutput Type or string (a GraphQL type inside the schema)Yes
requiredWhenever the field is non-nullablebooleanNo

Field argument

PropertyDescriptionTypeRequired
typeType of the argumentInput type or string (a GraphQL type inside the schema)No*
listList item typeList typeNo*
deprecationReasonReason why argument is deprecatedstringNo

* Either type or list is required.

Field argument item type

PropertyDescriptionTypeRequired
typeGraphQLList typeInput type or string (a GraphQL type inside the schema)Yes
requiredWhenever the field is non-nullablebooleanNo

Input object field type

PropertyDescriptionTypeRequired
typeType of the fieldInput type or string (a GraphQL type inside the schema)No*
listList item typeItem typeNo*
requiredWhenever the field is non-nullablebooleanNo
defaultValueDefault field valueunknownNo
deprecationReasonReason why argument is deprecatedstringNo

* Either type or list is required.

Input object field item type

PropertyDescriptionTypeRequired
typeGraphQLList typeInput type or string (a GraphQL type inside the schema)Yes
requiredWhenever the field is non-nullablebooleanNo

Options

PropertyDescriptionTypeRequired
contextPre-fill the context with custom types that graphql-json can use to resolve typesobjectNo
descriptionSchema descriptionstringNo
typesSchema description typesArray of GraphQLNamedType or stringNo
directivesSchema directivesArray of GraphQLDirectiveNo
extensionsSchena extensionGraphQLSchemaExtensionsNo
astNodeSchema astNodeSchemaDefinitionNodeNo
extensionASTNodesSchema extensionASTNodesSchemaExtensionNodeNo
0.0.7

11 months ago

0.0.6

11 months ago

0.0.5

11 months ago

0.0.4

11 months ago

0.0.3

11 months ago

0.0.2

11 months ago

0.0.1

11 months ago