Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ability to pass Internal and External types into Scalar #381

Merged
merged 1 commit into from
Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/ScalarTypeComposer.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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