Skip to content

Commit d9e9857

Browse files
committed
✨ Add response sanity check to remote schema fetching
1 parent 6724ae4 commit d9e9857

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/diff.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
introspectionQuery,
77
buildClientSchema,
88
buildSchema,
9-
IntrospectionQuery,
109
DangerousChange,
1110
BreakingChange
1211
} from 'graphql';
@@ -37,8 +36,13 @@ async function fetchRemoteSchema(
3736
throw new Error(`${res.status} - ${res.statusText} (${endpoint})`);
3837
}
3938

40-
const { data }: { data: IntrospectionQuery } = await res.json();
41-
return buildClientSchema(data);
39+
const responseBody = await res.json();
40+
41+
if (!responseBody || !responseBody.data || !responseBody.data.__schema) {
42+
throw new Error(`Invalid response from GraphQL endpoint: ${endpoint}`);
43+
}
44+
45+
return buildClientSchema(responseBody.data);
4246
}
4347

4448
function readLocalSchema(schemaPath: string): GraphQLSchema {

0 commit comments

Comments
 (0)