Skip to content

Commit 50335ab

Browse files
committed
Simplify + fix Flow types
1 parent ae5b163 commit 50335ab

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/utilities/extendSchema.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -199,17 +199,10 @@ export function extendSchema(
199199
const extendTypeCache = Object.create(null);
200200

201201
// Get the extended root operation types.
202-
const existingQueryType = schema.getQueryType();
203-
const existingMutationType = schema.getMutationType();
204-
const existingSubscriptionType = schema.getSubscriptionType();
205202
const operationTypes = {
206-
query: existingQueryType ? getExtendedType(existingQueryType) : null,
207-
mutation: existingMutationType
208-
? getExtendedType(existingMutationType)
209-
: null,
210-
subscription: existingSubscriptionType
211-
? getExtendedType(existingSubscriptionType)
212-
: null,
203+
query: getExtendedMaybeType(schema.getQueryType()),
204+
mutation: getExtendedMaybeType(schema.getMutationType()),
205+
subscription: getExtendedMaybeType(schema.getSubscriptionType()),
213206
};
214207

215208
// Then, incorporate all schema extensions.
@@ -220,7 +213,11 @@ export function extendSchema(
220213
if (operationTypes[operation]) {
221214
throw new Error(`Must provide only one ${operation} type in schema.`);
222215
}
223-
operationTypes[operation] = astBuilder.buildType(operationType.type);
216+
const typeRef = operationType.type;
217+
// Note: While this could make early assertions to get the correctly
218+
// typed values, that would throw immediately while type system
219+
// validation with validateSchema() will produce more actionable results.
220+
operationTypes[operation] = (astBuilder.buildType(typeRef): any);
224221
});
225222
}
226223
});
@@ -265,6 +262,10 @@ export function extendSchema(
265262
);
266263
}
267264

265+
function getExtendedMaybeType<T: GraphQLNamedType>(type: ?T): ?T {
266+
return type ? getExtendedType(type) : null;
267+
}
268+
268269
function getExtendedType<T: GraphQLNamedType>(type: T): T {
269270
if (!extendTypeCache[type.name]) {
270271
extendTypeCache[type.name] = extendType(type);

0 commit comments

Comments
 (0)