forked from gatsbyjs/gatsby
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(gatsby): Migrate type-builders to TypeScript (gatsbyjs#23892)
* chore(gatsby): Migrate type-builders to TypeScript * chore(gatsby): Migrate type-builders to TypeScript Co-authored-by: Blaine Kasten <blainekasten@gmail.com>
- Loading branch information
1 parent
cb282f5
commit 2ef310b
Showing
15 changed files
with
135 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/gatsby/src/schema/extensions/__tests__/child-relations.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/gatsby/src/schema/extensions/__tests__/field-extensions.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import { | ||
ComposeObjectTypeConfig, | ||
ComposeInputObjectTypeConfig, | ||
ComposeInterfaceTypeConfig, | ||
ComposeUnionTypeConfig, | ||
ComposeEnumTypeConfig, | ||
ComposeScalarTypeConfig, | ||
} from "graphql-compose" | ||
|
||
enum GatsbyGraphQLTypeKind { | ||
OBJECT = `OBJECT`, | ||
INPUT_OBJECT = `INPUT_OBJECT`, | ||
UNION = `UNION`, | ||
INTERFACE = `INTERFACE`, | ||
ENUM = `ENUM`, | ||
SCALAR = `SCALAR`, | ||
} | ||
|
||
export type GatsbyGraphQLType<TSource, TContext> = | ||
| { | ||
kind: GatsbyGraphQLTypeKind.OBJECT | ||
config: ComposeObjectTypeConfig<TSource, TContext> | ||
} | ||
| { | ||
kind: GatsbyGraphQLTypeKind.INPUT_OBJECT | ||
config: ComposeInputObjectTypeConfig | ||
} | ||
| { | ||
kind: GatsbyGraphQLTypeKind.UNION | ||
config: ComposeUnionTypeConfig<TSource, TContext> | ||
} | ||
| { | ||
kind: GatsbyGraphQLTypeKind.INTERFACE | ||
config: ComposeInterfaceTypeConfig<TSource, TContext> | ||
} | ||
| { | ||
kind: GatsbyGraphQLTypeKind.ENUM | ||
config: ComposeEnumTypeConfig | ||
} | ||
| { | ||
kind: GatsbyGraphQLTypeKind.SCALAR | ||
config: ComposeScalarTypeConfig | ||
} | ||
|
||
function buildObjectType<TSource, TContext>( | ||
config: ComposeObjectTypeConfig<TSource, TContext> | ||
): GatsbyGraphQLType<TSource, TContext> { | ||
return { | ||
kind: GatsbyGraphQLTypeKind.OBJECT, | ||
config, | ||
} | ||
} | ||
|
||
function buildUnionType<TSource, TContext>( | ||
config: ComposeUnionTypeConfig<TSource, TContext> | ||
): GatsbyGraphQLType<TSource, TContext> { | ||
return { | ||
kind: GatsbyGraphQLTypeKind.UNION, | ||
config, | ||
} | ||
} | ||
|
||
function buildInterfaceType<TSource, TContext>( | ||
config: ComposeInterfaceTypeConfig<TSource, TContext> | ||
): GatsbyGraphQLType<TSource, TContext> { | ||
return { | ||
kind: GatsbyGraphQLTypeKind.INTERFACE, | ||
config, | ||
} | ||
} | ||
|
||
function buildInputObjectType<TSource, TContext>( | ||
config: ComposeInputObjectTypeConfig | ||
): GatsbyGraphQLType<TSource, TContext> { | ||
return { | ||
kind: GatsbyGraphQLTypeKind.INPUT_OBJECT, | ||
config, | ||
} | ||
} | ||
|
||
function buildEnumType<TSource, TContext>( | ||
config: ComposeEnumTypeConfig | ||
): GatsbyGraphQLType<TSource, TContext> { | ||
return { | ||
kind: GatsbyGraphQLTypeKind.ENUM, | ||
config, | ||
} | ||
} | ||
|
||
function buildScalarType<TSource, TContext>( | ||
config: ComposeScalarTypeConfig | ||
): GatsbyGraphQLType<TSource, TContext> { | ||
return { | ||
kind: GatsbyGraphQLTypeKind.SCALAR, | ||
config, | ||
} | ||
} | ||
|
||
function isGatsbyType(something: any): something is GatsbyGraphQLTypeKind { | ||
return ( | ||
typeof something === `object` && | ||
something.kind && | ||
GatsbyGraphQLTypeKind[something.kind] | ||
) | ||
} | ||
|
||
export { | ||
GatsbyGraphQLTypeKind, | ||
buildObjectType, | ||
buildUnionType, | ||
buildInterfaceType, | ||
buildInputObjectType, | ||
buildEnumType, | ||
buildScalarType, | ||
isGatsbyType, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters