Skip to content
This repository has been archived by the owner on Apr 15, 2020. It is now read-only.

Commit

Permalink
refactor(transforms): standardize sourceSchema argument
Browse files Browse the repository at this point in the history
  • Loading branch information
yaacovCR committed Mar 26, 2020
1 parent 8754452 commit 60e04d6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
16 changes: 8 additions & 8 deletions src/transforms/AddArgumentsAsVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@ import { transformInputValue } from '../utils';
export default class AddArgumentsAsVariablesTransform implements Transform {
private targetSchema: GraphQLSchema;
private args: { [key: string]: any };
private newSchema: GraphQLSchema;
private sourceSchema: GraphQLSchema;

constructor(targetSchema: GraphQLSchema, args: { [key: string]: any }, newSchema: GraphQLSchema) {
constructor(targetSchema: GraphQLSchema, args: { [key: string]: any }, sourceSchema: GraphQLSchema) {
this.targetSchema = targetSchema;
this.args = args;
this.newSchema = newSchema;
this.sourceSchema = sourceSchema;
}

public transformRequest(originalRequest: Request): Request {
const { document, newVariables } = addVariablesToRootField(
this.targetSchema,
originalRequest.document,
this.args,
this.newSchema,
this.sourceSchema,
);
const variables = {
...originalRequest.variables,
Expand All @@ -54,7 +54,7 @@ function addVariablesToRootField(
targetSchema: GraphQLSchema,
document: DocumentNode,
args: { [key: string]: any },
newSchema: GraphQLSchema,
sourceSchema: GraphQLSchema,
): {
document: DocumentNode;
newVariables: { [key: string]: any };
Expand Down Expand Up @@ -138,13 +138,13 @@ function addVariablesToRootField(
},
type: typeToAst(argument.type),
};
if (newSchema) {
if (sourceSchema) {
newVariables[variableName] = transformInputValue(
argument.type,
args[argument.name],
(t, v) => {
const newType = newSchema.getType(t.name) as GraphQLEnumType | GraphQLScalarType;
return newType ? newType.serialize(v) : v;
const type = sourceSchema.getType(t.name) as GraphQLEnumType | GraphQLScalarType;
return type ? type.serialize(v) : v;
}
);
} else {
Expand Down
10 changes: 5 additions & 5 deletions src/transforms/ExpandAbstractTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ export default class ExpandAbstractTypes implements Transform {
private mapping: TypeMapping;
private reverseMapping: TypeMapping;

constructor(transformedSchema: GraphQLSchema, targetSchema: GraphQLSchema) {
constructor(sourceSchema: GraphQLSchema, targetSchema: GraphQLSchema) {
this.targetSchema = targetSchema;
this.mapping = extractPossibleTypes(transformedSchema, targetSchema);
this.mapping = extractPossibleTypes(sourceSchema, targetSchema);
this.reverseMapping = flipMapping(this.mapping);
}

Expand All @@ -44,17 +44,17 @@ export default class ExpandAbstractTypes implements Transform {
}

function extractPossibleTypes(
transformedSchema: GraphQLSchema,
sourceSchema: GraphQLSchema,
targetSchema: GraphQLSchema,
) {
const typeMap = transformedSchema.getTypeMap();
const typeMap = sourceSchema.getTypeMap();
const mapping: TypeMapping = {};
Object.keys(typeMap).forEach(typeName => {
const type = typeMap[typeName];
if (isAbstractType(type)) {
const targetType = targetSchema.getType(typeName);
if (!isAbstractType(targetType)) {
const implementations = transformedSchema.getPossibleTypes(type) || [];
const implementations = sourceSchema.getPossibleTypes(type) || [];
mapping[typeName] = implementations
.filter(impl => targetSchema.getType(impl.name))
.map(impl => impl.name);
Expand Down

0 comments on commit 60e04d6

Please sign in to comment.