mirror of
https://github.com/graphql-hive/console
synced 2026-05-23 17:18:23 +00:00
Explain why comparison of versions failed (#701)
This commit is contained in:
parent
6be629baf7
commit
06b68fce21
3 changed files with 57 additions and 9 deletions
|
|
@ -8,6 +8,7 @@ import {
|
|||
isInputObjectType,
|
||||
isScalarType,
|
||||
GraphQLNamedType,
|
||||
GraphQLError,
|
||||
} from 'graphql';
|
||||
import type { SchemaModule } from './__generated__/types';
|
||||
import { SchemaManager } from './providers/schema-manager';
|
||||
|
|
@ -575,7 +576,26 @@ export const resolvers: SchemaModule.Resolvers = {
|
|||
return [];
|
||||
}
|
||||
|
||||
return injector.get(Inspector).diff(buildSchema(before), buildSchema(after));
|
||||
const previousSchema = buildSchema(
|
||||
before,
|
||||
error =>
|
||||
new GraphQLError(
|
||||
`Failed to build the previous version: ${
|
||||
error instanceof GraphQLError ? error.message : error
|
||||
}`,
|
||||
),
|
||||
);
|
||||
const currentSchema = buildSchema(
|
||||
after,
|
||||
error =>
|
||||
new GraphQLError(
|
||||
`Failed to build the selected version: ${
|
||||
error instanceof GraphQLError ? error.message : error
|
||||
}`,
|
||||
),
|
||||
);
|
||||
|
||||
return injector.get(Inspector).diff(previousSchema, currentSchema);
|
||||
},
|
||||
diff([before, after]) {
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -24,13 +24,20 @@ export function hashSchema(schema: Schema): string {
|
|||
/**
|
||||
* Builds GraphQLSchema without validation of SDL
|
||||
*/
|
||||
export function buildSchema(schema: SchemaObject): GraphQLSchema {
|
||||
return lexicographicSortSchema(
|
||||
buildASTSchema(schema.document, {
|
||||
assumeValid: true,
|
||||
assumeValidSDL: true,
|
||||
}),
|
||||
);
|
||||
export function buildSchema(
|
||||
schema: SchemaObject,
|
||||
transformError = (error: unknown) => error,
|
||||
): GraphQLSchema {
|
||||
try {
|
||||
return lexicographicSortSchema(
|
||||
buildASTSchema(schema.document, {
|
||||
assumeValid: true,
|
||||
assumeValidSDL: true,
|
||||
}),
|
||||
);
|
||||
} catch (error) {
|
||||
throw transformError(error);
|
||||
}
|
||||
}
|
||||
|
||||
export function findSchema(schemas: readonly Schema[], expected: Schema): Schema | undefined {
|
||||
|
|
|
|||
|
|
@ -95,6 +95,24 @@ const DiffView = ({
|
|||
},
|
||||
});
|
||||
const comparison = compareQuery.data?.schemaCompareToPrevious;
|
||||
const error = compareQuery.error;
|
||||
|
||||
if (error) {
|
||||
return (
|
||||
<div className="m-3 rounded-lg bg-red-500/20 p-8">
|
||||
<div className="mb-3 flex items-center gap-3">
|
||||
<VscBug className="h-8 w-8 text-red-500" />
|
||||
<h2 className="text-lg font-medium text-white">Failed to compare schemas</h2>
|
||||
</div>
|
||||
<p className="text-base text-gray-500">
|
||||
Previous or current schema is most likely incomplete and was force published
|
||||
</p>
|
||||
<pre className="mt-5 rounded-lg bg-red-900 p-3 text-xs text-white">
|
||||
{error.graphQLErrors[0].message}
|
||||
</pre>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (!comparison) {
|
||||
return null;
|
||||
|
|
@ -108,8 +126,11 @@ const DiffView = ({
|
|||
<h2 className="text-lg font-medium text-white">Failed to build GraphQL Schema</h2>
|
||||
</div>
|
||||
<p className="text-base text-gray-500">
|
||||
Schema is most likely incomplete and was force published
|
||||
Previous or current schema is most likely incomplete and was force published
|
||||
</p>
|
||||
<pre className="mt-5 rounded-lg bg-red-900 p-3 text-xs text-white">
|
||||
{comparison.message}
|
||||
</pre>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue