diff --git a/examples/starwars.ts b/examples/starwars.ts index 26acd50..81cdcc7 100644 --- a/examples/starwars.ts +++ b/examples/starwars.ts @@ -1,4 +1,4 @@ -import type { Interface } from '../src'; +import type { InterfaceType } from '../src'; import type { Connection, ConnectionArguments, Edge } from '../src/relay'; import { buildGraphQLSchema, Gql } from '../src'; import { @@ -10,7 +10,7 @@ import express = require('express'); import graphqlHTTP = require('express-graphql'); declare module '../src/types' { - interface Context { + interface GqlContext { contextContent: string; } } @@ -154,7 +154,7 @@ const episodeEnum = Gql.Enum({ ], }); -const characterInterface: Interface = +const characterInterface: InterfaceType = Gql.InterfaceType({ name: 'Character', interfaces: [], diff --git a/src/build.ts b/src/build.ts index e88e0dd..3af9a0a 100644 --- a/src/build.ts +++ b/src/build.ts @@ -6,11 +6,11 @@ import { AllType, DefaultArgument, Argument, - SubscriptionObject, + SubscriptionObjectType, ArgMap, - Context, - Union, - Interface, + GqlContext, + UnionType, + InterfaceType, } from './types'; export function buildGraphQLSchema( @@ -64,13 +64,13 @@ export function toGraphQLArgs( } export function toGraphQLSubscriptionObject( - subscriptionObj: SubscriptionObject, + subscriptionObj: SubscriptionObjectType, typeMap: Map ): graphql.GraphQLObjectType { return new graphql.GraphQLObjectType({ name: subscriptionObj.name, fields: () => { - const gqlFieldConfig: graphql.GraphQLFieldConfigMap = + const gqlFieldConfig: graphql.GraphQLFieldConfigMap = {}; subscriptionObj.fields().forEach((field) => { @@ -190,7 +190,7 @@ export function toGraphQLOutputType( isTypeOf: t.isTypeOf, fields: () => { const fields = t.fieldsFn(); - const gqlFieldConfig: graphql.GraphQLFieldConfigMap = + const gqlFieldConfig: graphql.GraphQLFieldConfigMap = {}; fields.forEach((field) => { @@ -231,7 +231,7 @@ export function toGraphQLOutputType( src, ctx, info, - ourType as Union | Interface + ourType as UnionType | InterfaceType ); } : undefined, @@ -245,7 +245,7 @@ export function toGraphQLOutputType( description: t.description, fields: () => { const fields = t.fieldsFn(); - const result: graphql.GraphQLFieldConfigMap = {}; + const result: graphql.GraphQLFieldConfigMap = {}; fields.forEach((field) => { result[field.name] = { @@ -275,7 +275,7 @@ export function toGraphQLOutputType( src, ctx, info, - ourType as Union | Interface + ourType as UnionType | InterfaceType ); } : undefined, diff --git a/src/define.ts b/src/define.ts index c2bf2c4..252d909 100644 --- a/src/define.ts +++ b/src/define.ts @@ -1,12 +1,12 @@ import * as graphql from 'graphql'; import { - Scalar, - Enum, + ScalarType, + EnumType, EnumValue, ObjectType, - InputObject, - Interface, - Union, + InputObjectType, + InterfaceType, + UnionType, InputType, OutputType, ArgMap, @@ -17,9 +17,9 @@ import { Argument, InputFieldMap, SubscriptionField, - SubscriptionObject, + SubscriptionObjectType, PromiseOrValue, - Context, + GqlContext, } from './types'; type ExtensionsMap = { @@ -35,7 +35,7 @@ type ResolvePartialMandatory = { resolve: ( src: Src, args: TOfArgMap>, - ctx: Context, + ctx: GqlContext, info: graphql.GraphQLResolveInfo ) => PromiseOrValue; }; @@ -44,14 +44,14 @@ type ResolvePartialOptional = { resolve?: ( src: Src, args: TOfArgMap>, - ctx: Context, + ctx: GqlContext, info: graphql.GraphQLResolveInfo ) => PromiseOrValue; }; function builtInScalar( builtInType: graphql.GraphQLScalarType -): Scalar { +): ScalarType { return { kind: 'Scalar', builtInType, @@ -59,22 +59,22 @@ function builtInScalar( } export namespace Gql { - export const String: Scalar = + export const String: ScalarType = builtInScalar(graphql.GraphQLString); - export const Int: Scalar = builtInScalar( + export const Int: ScalarType = builtInScalar( graphql.GraphQLInt ); - export const Float: Scalar = builtInScalar( + export const Float: ScalarType = builtInScalar( graphql.GraphQLFloat ); - export const Boolean: Scalar = + export const Boolean: ScalarType = builtInScalar(graphql.GraphQLBoolean); - export const ID: Scalar = builtInScalar( + export const ID: ScalarType = builtInScalar( graphql.GraphQLID ); - export function ScalarType({ + export function Scalar({ name, description, serialize, @@ -86,7 +86,7 @@ export namespace Gql { serialize: (src: Src) => any | null; parseValue?: (value: unknown) => Src | null; parseLiteral?: (value: graphql.ValueNode) => Src | null; - }): Scalar { + }): ScalarType { return { kind: 'Scalar', graphqlTypeConfig: { @@ -107,7 +107,7 @@ export namespace Gql { name: string; description?: string; values: Array>; - }): Enum { + }): EnumType { return { kind: 'Enum', name, @@ -210,13 +210,13 @@ export namespace Gql { }: { name: string; description?: string; - interfaces?: Array>; + interfaces?: Array>; fields: ( self: OutputType ) => [Field, ...Field[]]; isTypeOf?: ( src: any, - ctx: Context, + ctx: GqlContext, info: graphql.GraphQLResolveInfo ) => boolean; extensions?: ExtensionsMap['objectType'] extends undefined @@ -245,8 +245,8 @@ export namespace Gql { name: string; description?: string; fields: (self: InputType) => InputFieldMap; - }): InputObject { - let inputObj: InputObject = { + }): InputObjectType { + let inputObj: InputObjectType = { kind: 'InputObject', name, description, @@ -267,14 +267,14 @@ export namespace Gql { description?: string; types: Array> | (() => Array>); resolveType: (src: Src) => string; - }): Union { + }): UnionType { return { kind: 'Union', name, description, types, resolveType, - } as Union; + } as UnionType; } export function InterfaceType({ @@ -285,10 +285,10 @@ export namespace Gql { }: { name: string; description?: string; - interfaces?: Array> | (() => Array>); - fields: (self: Interface) => Array>; - }): Interface { - const obj: Interface = { + interfaces?: Array> | (() => Array>); + fields: (self: InterfaceType) => Array>; + }): InterfaceType { + const obj: InterfaceType = { kind: 'Interface', name, description, @@ -388,7 +388,7 @@ export namespace Gql { subscribe: ( src: RootSrc, args: TOfArgMap>, - ctx: Context, + ctx: GqlContext, info: graphql.GraphQLResolveInfo ) => PromiseOrValue>; }): SubscriptionField { @@ -413,7 +413,7 @@ export namespace Gql { SubscriptionField, ...SubscriptionField[] ]; - }): SubscriptionObject { + }): SubscriptionObjectType { return { kind: 'SubscriptionObject', name, diff --git a/src/relay.ts b/src/relay.ts index 373026e..1eb6db9 100644 --- a/src/relay.ts +++ b/src/relay.ts @@ -1,9 +1,9 @@ import type { Field, - Interface, + InterfaceType, Argument, TOfArgMap, - Context, + GqlContext, ObjectType, } from './types'; import { Gql } from './define'; @@ -14,7 +14,7 @@ import { GraphQLResolveInfo } from 'graphql'; export type ConnectionConfig = { name?: string; - nodeType: ObjectType | Interface; + nodeType: ObjectType | InterfaceType; edgeFields?: () => Array, any, any>>; connectionFields?: () => Array, any, any>>; }; @@ -58,7 +58,7 @@ export type RelayConnectionDefinitions = { export function nodeDefinitions( idFetcher: ( id: string, - context: Context, + context: GqlContext, info: GraphQLResolveInfo ) => Promise | Src ) { diff --git a/src/types.ts b/src/types.ts index 486fd7a..cdff205 100644 --- a/src/types.ts +++ b/src/types.ts @@ -3,24 +3,24 @@ import * as graphql from 'graphql'; export type PromiseOrValue = Promise | T; type Maybe = T | null | undefined; -export interface Context {} +export interface GqlContext {} export type OutputType = - | Scalar - | Enum + | ScalarType + | EnumType | ObjectType - | Union - | Interface - | ListType - | NonNullType; + | UnionType + | InterfaceType + | ListOutput + | NonNullOutput; -interface ListType extends List> {} -interface NonNullType extends NonNull> {} +interface ListOutput extends List> {} +interface NonNullOutput extends NonNull> {} export type InputType = - | Scalar - | Enum - | InputObject + | ScalarType + | EnumType + | InputObjectType | ListInputType | NonNullInputType; @@ -29,7 +29,7 @@ interface NonNullInputType extends NonNullInput> {} export type AllType = OutputType | InputType; -export type Scalar = +export type ScalarType = | { kind: 'Scalar'; graphqlTypeConfig: graphql.GraphQLScalarTypeConfig; @@ -39,7 +39,7 @@ export type Scalar = builtInType: graphql.GraphQLScalarType; }; -export type Enum = { +export type EnumType = { kind: 'Enum'; name: string; description?: string; @@ -113,7 +113,7 @@ export type Field = { resolve?: ( src: Src, args: TOfArgMap>, - ctx: Context, + ctx: GqlContext, info: graphql.GraphQLResolveInfo ) => Out | Promise; extensions?: Record; @@ -133,11 +133,11 @@ export type ObjectType = { name: string; description?: string; deprecationReason?: string; - interfaces: Array> | (() => Array>); + interfaces: Array> | (() => Array>); fieldsFn: () => Array>; isTypeOf?: ( src: any, - ctx: Context, + ctx: GqlContext, info: graphql.GraphQLResolveInfo ) => boolean | Promise; extensions?: Record; @@ -153,7 +153,7 @@ export type InputFieldMap = { [K in keyof T]: InputField; }; -export type InputObject = { +export type InputObjectType = { kind: 'InputObject'; name: string; description?: string; @@ -162,21 +162,21 @@ export type InputObject = { export type ResolveType = ( src: Src, - ctx: Context, + ctx: GqlContext, info: graphql.GraphQLResolveInfo, - abstractType: Union | Interface + abstractType: UnionType | InterfaceType ) => PromiseOrValue; -export type Interface = { +export type InterfaceType = { kind: 'Interface'; name: string; description?: string; - interfaces: Array> | (() => Array>); + interfaces: Array> | (() => Array>); fieldsFn: () => Array>; resolveType?: ResolveType; }; -export type Union = { +export type UnionType = { kind: 'Union'; name: string; description?: string; @@ -184,7 +184,7 @@ export type Union = { resolveType: ResolveType; }; -export type SubscriptionObject = { +export type SubscriptionObjectType = { kind: 'SubscriptionObject'; name: string; fields: () => Array>; @@ -200,13 +200,13 @@ export type SubscriptionField = { subscribe: ( source: RootSrc, args: TOfArgMap>, - ctx: Context, + ctx: GqlContext, info: graphql.GraphQLResolveInfo ) => PromiseOrValue>; resolve: ( source: Out, args: TOfArgMap>, - ctx: Context, + ctx: GqlContext, info: graphql.GraphQLResolveInfo ) => PromiseOrValue; }; @@ -214,7 +214,7 @@ export type SubscriptionField = { export type Schema = { query: ObjectType; mutation?: ObjectType; - subscription?: SubscriptionObject; + subscription?: SubscriptionObjectType; types?: ObjectType[]; directives?: graphql.GraphQLDirective[]; }; diff --git a/test/simple.spec.ts b/test/simple.spec.ts index b0da7e1..6b220a0 100644 --- a/test/simple.spec.ts +++ b/test/simple.spec.ts @@ -1,11 +1,11 @@ import { execute, parse, printSchema, subscribe } from 'graphql'; import * as relay from '../src/relay'; import { Gql } from '../src/define'; -import { Interface } from '../src/types'; +import { InterfaceType } from '../src/types'; import { buildGraphQLSchema } from '../src/build'; declare module '../src/types' { - interface Context { + interface GqlContext { contextContent: string; } } @@ -153,7 +153,7 @@ test('can build a schema', async () => { ], }); - const characterInterface: Interface = + const characterInterface: InterfaceType = Gql.InterfaceType({ name: 'Character', interfaces: [],