-
Notifications
You must be signed in to change notification settings - Fork 242
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove dependency on
apollo-graphql
and port over functions (#1364)
* remove dependencies on `apollo-graphql` and port over functions as required
- Loading branch information
Showing
26 changed files
with
690 additions
and
32 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { GraphQLFieldResolver, GraphQLScalarType, DocumentNode } from 'graphql'; | ||
|
||
export interface GraphQLSchemaModule { | ||
typeDefs: DocumentNode; | ||
resolvers?: GraphQLResolverMap<any>; | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
export interface GraphQLResolverMap<TContext = {}> { | ||
[typeName: string]: | ||
| { | ||
[fieldName: string]: | ||
| GraphQLFieldResolver<any, TContext> | ||
| { | ||
requires?: string; | ||
resolve: GraphQLFieldResolver<any, TContext>; | ||
}; | ||
} | ||
| GraphQLScalarType | ||
| { | ||
[enumValue: string]: string | number; | ||
}; | ||
} |
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
gateway-js/src/datasources/__tests__/LocalGraphQLDataSource.test.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { | ||
GraphQLSchema, | ||
isObjectType, | ||
GraphQLEnumType, | ||
isAbstractType, | ||
isScalarType, | ||
isEnumType, | ||
GraphQLEnumValueConfig, | ||
} from 'graphql'; | ||
|
||
import { GraphQLResolverMap } from './resolverMap'; | ||
|
||
export function addResolversToSchema( | ||
schema: GraphQLSchema, | ||
resolvers: GraphQLResolverMap<any> | ||
) { | ||
for (const [typeName, fieldConfigs] of Object.entries(resolvers)) { | ||
const type = schema.getType(typeName); | ||
|
||
if (isAbstractType(type)) { | ||
for (const [fieldName, fieldConfig] of Object.entries(fieldConfigs)) { | ||
if (fieldName.startsWith("__")) { | ||
(type as any)[fieldName.substring(2)] = fieldConfig; | ||
} | ||
} | ||
} | ||
|
||
if (isScalarType(type)) { | ||
for (const fn in fieldConfigs) { | ||
(type as any)[fn] = (fieldConfigs as any)[fn]; | ||
} | ||
} | ||
|
||
if (isEnumType(type)) { | ||
const values = type.getValues(); | ||
const newValues: { [key: string]: GraphQLEnumValueConfig } = {}; | ||
values.forEach(value => { | ||
let newValue = (fieldConfigs as any)[value.name]; | ||
if (newValue === undefined) { | ||
newValue = value.name; | ||
} | ||
|
||
newValues[value.name] = { | ||
value: newValue, | ||
deprecationReason: value.deprecationReason, | ||
description: value.description, | ||
astNode: value.astNode, | ||
extensions: undefined | ||
}; | ||
}); | ||
|
||
// In place updating hack to get around pulling in the full | ||
// schema walking and immutable updating machinery from graphql-tools | ||
Object.assign( | ||
type, | ||
new GraphQLEnumType({ | ||
...type.toConfig(), | ||
values: newValues | ||
}) | ||
); | ||
} | ||
|
||
if (!isObjectType(type)) continue; | ||
|
||
const fieldMap = type.getFields(); | ||
|
||
for (const [fieldName, fieldConfig] of Object.entries(fieldConfigs)) { | ||
if (fieldName.startsWith("__")) { | ||
(type as any)[fieldName.substring(2)] = fieldConfig; | ||
continue; | ||
} | ||
|
||
const field = fieldMap[fieldName]; | ||
if (!field) continue; | ||
|
||
if (typeof fieldConfig === "function") { | ||
field.resolve = fieldConfig; | ||
} else { | ||
field.resolve = fieldConfig.resolve; | ||
} | ||
} | ||
} | ||
} |
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,11 @@ | ||
import { GraphQLError } from "graphql"; | ||
|
||
export class GraphQLSchemaValidationError extends Error { | ||
constructor(public errors: ReadonlyArray<GraphQLError>) { | ||
super(); | ||
|
||
this.name = this.constructor.name; | ||
Error.captureStackTrace(this, this.constructor); | ||
this.message = errors.map(error => error.message).join("\n\n"); | ||
} | ||
} |
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,3 @@ | ||
export * from './resolverMap'; | ||
export * from './addResolversToSchema'; | ||
export * from './error'; |
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,23 @@ | ||
import { GraphQLFieldResolver, GraphQLScalarType, DocumentNode } from 'graphql'; | ||
|
||
export interface GraphQLSchemaModule { | ||
typeDefs: DocumentNode; | ||
resolvers?: GraphQLResolverMap<any>; | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
export interface GraphQLResolverMap<TContext = {}> { | ||
[typeName: string]: | ||
| { | ||
[fieldName: string]: | ||
| GraphQLFieldResolver<any, TContext> | ||
| { | ||
requires?: string; | ||
resolve: GraphQLFieldResolver<any, TContext>; | ||
}; | ||
} | ||
| GraphQLScalarType | ||
| { | ||
[enumValue: string]: string | number; | ||
}; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
Oops, something went wrong.