Skip to content

Commit

Permalink
add Type suffix to ts types. Context -> GqlContext
Browse files Browse the repository at this point in the history
  • Loading branch information
sikanhe committed Dec 5, 2023
1 parent 604b993 commit 7a793f8
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 77 deletions.
6 changes: 3 additions & 3 deletions examples/starwars.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -10,7 +10,7 @@ import express = require('express');
import graphqlHTTP = require('express-graphql');

declare module '../src/types' {
interface Context {
interface GqlContext {
contextContent: string;
}
}
Expand Down Expand Up @@ -154,7 +154,7 @@ const episodeEnum = Gql.Enum({
],
});

const characterInterface: Interface<ICharacter | null> =
const characterInterface: InterfaceType<ICharacter | null> =
Gql.InterfaceType<ICharacter>({
name: 'Character',
interfaces: [],
Expand Down
20 changes: 10 additions & 10 deletions src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import {
AllType,
DefaultArgument,
Argument,
SubscriptionObject,
SubscriptionObjectType,
ArgMap,
Context,
Union,
Interface,
GqlContext,
UnionType,
InterfaceType,
} from './types';

export function buildGraphQLSchema<RootSrc>(
Expand Down Expand Up @@ -64,13 +64,13 @@ export function toGraphQLArgs<T>(
}

export function toGraphQLSubscriptionObject<RootSrc>(
subscriptionObj: SubscriptionObject<RootSrc>,
subscriptionObj: SubscriptionObjectType<RootSrc>,
typeMap: Map<AllType, graphql.GraphQLType>
): graphql.GraphQLObjectType {
return new graphql.GraphQLObjectType({
name: subscriptionObj.name,
fields: () => {
const gqlFieldConfig: graphql.GraphQLFieldConfigMap<RootSrc, Context> =
const gqlFieldConfig: graphql.GraphQLFieldConfigMap<RootSrc, GqlContext> =
{};

subscriptionObj.fields().forEach((field) => {
Expand Down Expand Up @@ -190,7 +190,7 @@ export function toGraphQLOutputType<Src>(
isTypeOf: t.isTypeOf,
fields: () => {
const fields = t.fieldsFn();
const gqlFieldConfig: graphql.GraphQLFieldConfigMap<Src, Context> =
const gqlFieldConfig: graphql.GraphQLFieldConfigMap<Src, GqlContext> =
{};

fields.forEach((field) => {
Expand Down Expand Up @@ -231,7 +231,7 @@ export function toGraphQLOutputType<Src>(
src,
ctx,
info,
ourType as Union<any> | Interface<any>
ourType as UnionType<any> | InterfaceType<any>
);
}
: undefined,
Expand All @@ -245,7 +245,7 @@ export function toGraphQLOutputType<Src>(
description: t.description,
fields: () => {
const fields = t.fieldsFn();
const result: graphql.GraphQLFieldConfigMap<Src, Context> = {};
const result: graphql.GraphQLFieldConfigMap<Src, GqlContext> = {};

fields.forEach((field) => {
result[field.name] = {
Expand Down Expand Up @@ -275,7 +275,7 @@ export function toGraphQLOutputType<Src>(
src,
ctx,
info,
ourType as Union<any> | Interface<any>
ourType as UnionType<any> | InterfaceType<any>
);
}
: undefined,
Expand Down
60 changes: 30 additions & 30 deletions src/define.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -17,9 +17,9 @@ import {
Argument,
InputFieldMap,
SubscriptionField,
SubscriptionObject,
SubscriptionObjectType,
PromiseOrValue,
Context,
GqlContext,
} from './types';

type ExtensionsMap = {
Expand All @@ -35,7 +35,7 @@ type ResolvePartialMandatory<Src, Arg, Out> = {
resolve: (
src: Src,
args: TOfArgMap<ArgMap<Arg>>,
ctx: Context,
ctx: GqlContext,
info: graphql.GraphQLResolveInfo
) => PromiseOrValue<Out>;
};
Expand All @@ -44,37 +44,37 @@ type ResolvePartialOptional<Src, Arg, Out> = {
resolve?: (
src: Src,
args: TOfArgMap<ArgMap<Arg>>,
ctx: Context,
ctx: GqlContext,
info: graphql.GraphQLResolveInfo
) => PromiseOrValue<Out>;
};

function builtInScalar<Src>(
builtInType: graphql.GraphQLScalarType
): Scalar<Src | null> {
): ScalarType<Src | null> {
return {
kind: 'Scalar',
builtInType,
};
}

export namespace Gql {
export const String: Scalar<string | null | undefined> =
export const String: ScalarType<string | null | undefined> =
builtInScalar<string>(graphql.GraphQLString);
export const Int: Scalar<number | null | undefined> = builtInScalar<number>(
export const Int: ScalarType<number | null | undefined> = builtInScalar<number>(
graphql.GraphQLInt
);
export const Float: Scalar<number | null | undefined> = builtInScalar<number>(
export const Float: ScalarType<number | null | undefined> = builtInScalar<number>(
graphql.GraphQLFloat
);
export const Boolean: Scalar<boolean | null | undefined> =
export const Boolean: ScalarType<boolean | null | undefined> =
builtInScalar<boolean>(graphql.GraphQLBoolean);

export const ID: Scalar<string | null | undefined> = builtInScalar<string>(
export const ID: ScalarType<string | null | undefined> = builtInScalar<string>(
graphql.GraphQLID
);

export function ScalarType<Src>({
export function Scalar<Src>({
name,
description,
serialize,
Expand All @@ -86,7 +86,7 @@ export namespace Gql {
serialize: (src: Src) => any | null;
parseValue?: (value: unknown) => Src | null;
parseLiteral?: (value: graphql.ValueNode) => Src | null;
}): Scalar<Src | null> {
}): ScalarType<Src | null> {
return {
kind: 'Scalar',
graphqlTypeConfig: {
Expand All @@ -107,7 +107,7 @@ export namespace Gql {
name: string;
description?: string;
values: Array<EnumValue<Src>>;
}): Enum<Src | null> {
}): EnumType<Src | null> {
return {
kind: 'Enum',
name,
Expand Down Expand Up @@ -210,13 +210,13 @@ export namespace Gql {
}: {
name: string;
description?: string;
interfaces?: Array<Interface<any>>;
interfaces?: Array<InterfaceType<any>>;
fields: (
self: OutputType<Src | null>
) => [Field<Src, any, {}>, ...Field<Src, any, {}>[]];
isTypeOf?: (
src: any,
ctx: Context,
ctx: GqlContext,
info: graphql.GraphQLResolveInfo
) => boolean;
extensions?: ExtensionsMap['objectType'] extends undefined
Expand Down Expand Up @@ -245,8 +245,8 @@ export namespace Gql {
name: string;
description?: string;
fields: (self: InputType<Src | null>) => InputFieldMap<Src>;
}): InputObject<Src | null> {
let inputObj: InputObject<Src | null> = {
}): InputObjectType<Src | null> {
let inputObj: InputObjectType<Src | null> = {
kind: 'InputObject',
name,
description,
Expand All @@ -267,14 +267,14 @@ export namespace Gql {
description?: string;
types: Array<ObjectType<any>> | (() => Array<ObjectType<any>>);
resolveType: (src: Src) => string;
}): Union<Src | null> {
}): UnionType<Src | null> {
return {
kind: 'Union',
name,
description,
types,
resolveType,
} as Union<Src | null>;
} as UnionType<Src | null>;
}

export function InterfaceType<Src>({
Expand All @@ -285,10 +285,10 @@ export namespace Gql {
}: {
name: string;
description?: string;
interfaces?: Array<Interface<any>> | (() => Array<Interface<any>>);
fields: (self: Interface<Src | null>) => Array<AbstractField<any>>;
}): Interface<Src | null> {
const obj: Interface<Src | null> = {
interfaces?: Array<InterfaceType<any>> | (() => Array<InterfaceType<any>>);
fields: (self: InterfaceType<Src | null>) => Array<AbstractField<any>>;
}): InterfaceType<Src | null> {
const obj: InterfaceType<Src | null> = {
kind: 'Interface',
name,
description,
Expand Down Expand Up @@ -388,7 +388,7 @@ export namespace Gql {
subscribe: (
src: RootSrc,
args: TOfArgMap<ArgMap<Arg>>,
ctx: Context,
ctx: GqlContext,
info: graphql.GraphQLResolveInfo
) => PromiseOrValue<AsyncIterableIterator<Out>>;
}): SubscriptionField<RootSrc, Arg, Out> {
Expand All @@ -413,7 +413,7 @@ export namespace Gql {
SubscriptionField<Src, any, any>,
...SubscriptionField<Src, any, any>[]
];
}): SubscriptionObject<Src> {
}): SubscriptionObjectType<Src> {
return {
kind: 'SubscriptionObject',
name,
Expand Down
8 changes: 4 additions & 4 deletions src/relay.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type {
Field,
Interface,
InterfaceType,
Argument,
TOfArgMap,
Context,
GqlContext,
ObjectType,
} from './types';
import { Gql } from './define';
Expand All @@ -14,7 +14,7 @@ import { GraphQLResolveInfo } from 'graphql';

export type ConnectionConfig<T> = {
name?: string;
nodeType: ObjectType<T | null> | Interface<T | null>;
nodeType: ObjectType<T | null> | InterfaceType<T | null>;
edgeFields?: () => Array<Field<Edge<T>, any, any>>;
connectionFields?: () => Array<Field<Connection<T>, any, any>>;
};
Expand Down Expand Up @@ -58,7 +58,7 @@ export type RelayConnectionDefinitions<T> = {
export function nodeDefinitions<Src>(
idFetcher: (
id: string,
context: Context,
context: GqlContext,
info: GraphQLResolveInfo
) => Promise<Src> | Src
) {
Expand Down
Loading

0 comments on commit 7a793f8

Please sign in to comment.