Skip to content

Commit

Permalink
fix: add ability to pass Internal and External types into Scalar (#381)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilsprut committed Mar 28, 2022
1 parent 8527e31 commit c7cc845
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
17 changes: 10 additions & 7 deletions src/ScalarTypeComposer.ts
Expand Up @@ -17,12 +17,15 @@ import { graphqlVersion } from './utils/graphqlVersion';
import { printScalar, SchemaPrinterOptions } from './utils/schemaPrinter';
import { getScalarTypeDefinitionNode } from './utils/definitionNode';

export type ScalarTypeComposerDefinition =
export type ScalarTypeComposerDefinition<TInternal, TExternal> =
| TypeAsString
| Readonly<ScalarTypeComposerAsObjectDefinition>
| Readonly<ScalarTypeComposerAsObjectDefinition<TInternal, TExternal>>
| Readonly<GraphQLScalarType>;

export type ScalarTypeComposerAsObjectDefinition = GraphQLScalarTypeConfig<any, any> & {
export type ScalarTypeComposerAsObjectDefinition<TInternal, TExternal> = GraphQLScalarTypeConfig<
TInternal,
TExternal
> & {
extensions?: Extensions;
directives?: Directive[];
};
Expand All @@ -47,8 +50,8 @@ export class ScalarTypeComposer<TContext = any> {
* Create `ScalarTypeComposer` with adding it by name to the `SchemaComposer`.
* This type became available in SDL by its name.
*/
static create<TCtx = any>(
typeDef: ScalarTypeComposerDefinition,
static create<TCtx = any, TInternal = any, TExternal = any>(
typeDef: ScalarTypeComposerDefinition<TInternal, TExternal>,
schemaComposer: SchemaComposer<TCtx>
): ScalarTypeComposer<TCtx> {
if (!(schemaComposer instanceof SchemaComposer)) {
Expand All @@ -70,8 +73,8 @@ export class ScalarTypeComposer<TContext = any> {
* Create `ScalarTypeComposer` without adding it to the `SchemaComposer`.
* This method may be useful in plugins, when you need to create type temporary.
*/
static createTemp<TCtx = any>(
typeDef: ScalarTypeComposerDefinition,
static createTemp<TCtx = any, TInternal = any, TExternal = any>(
typeDef: ScalarTypeComposerDefinition<TInternal, TExternal>,
schemaComposer?: SchemaComposer<TCtx>
): ScalarTypeComposer<TCtx> {
const sc = schemaComposer || new SchemaComposer();
Expand Down
4 changes: 3 additions & 1 deletion src/SchemaComposer.ts
Expand Up @@ -555,7 +555,9 @@ export class SchemaComposer<TContext = any> extends TypeStorage<any, NamedTypeCo
return UnionTypeComposer.create(typeDef, this);
}

createScalarTC(typeDef: ScalarTypeComposerDefinition): ScalarTypeComposer<TContext> {
createScalarTC<TInternal = any, TExternal = any>(
typeDef: ScalarTypeComposerDefinition<TInternal, TExternal>
): ScalarTypeComposer<TContext> {
return ScalarTypeComposer.create(typeDef, this);
}

Expand Down

0 comments on commit c7cc845

Please sign in to comment.