This repository was archived by the owner on Feb 27, 2023. It is now read-only.
forked from graphql-java/graphql-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiffSet.java
More file actions
75 lines (64 loc) · 2.36 KB
/
DiffSet.java
File metadata and controls
75 lines (64 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package graphql.schema.diff;
import graphql.Assert;
import graphql.ExecutionResult;
import graphql.GraphQL;
import graphql.PublicApi;
import graphql.introspection.IntrospectionQuery;
import graphql.schema.GraphQLSchema;
import java.util.Map;
/**
* Represents 2 schemas that can be diffed. The {@link SchemaDiff} code
* assumes that that schemas to be diffed are the result of a
* {@link graphql.introspection.IntrospectionQuery}.
*/
@PublicApi
public class DiffSet {
private final Map<String, Object> introspectionOld;
private final Map<String, Object> introspectionNew;
public DiffSet(Map<String, Object> introspectionOld, Map<String, Object> introspectionNew) {
this.introspectionOld = introspectionOld;
this.introspectionNew = introspectionNew;
}
/**
* @return the old API as an introspection result
*/
public Map<String, Object> getOld() {
return introspectionOld;
}
/**
* @return the new API as an introspection result
*/
public Map<String, Object> getNew() {
return introspectionNew;
}
/**
* Creates a diff set out of the result of 2 introspection queries.
*
* @param introspectionOld the older introspection query
* @param introspectionNew the newer introspection query
*
* @return a diff set representing them
*/
public static DiffSet diffSet(Map<String, Object> introspectionOld, Map<String, Object> introspectionNew) {
return new DiffSet(introspectionOld, introspectionNew);
}
/**
* Creates a diff set out of the result of 2 schemas.
*
* @param schemaOld the older schema
* @param schemaNew the newer schema
*
* @return a diff set representing them
*/
public static DiffSet diffSet(GraphQLSchema schemaOld, GraphQLSchema schemaNew) {
Map<String, Object> introspectionOld = introspect(schemaOld);
Map<String, Object> introspectionNew = introspect(schemaNew);
return diffSet(introspectionOld, introspectionNew);
}
private static Map<String, Object> introspect(GraphQLSchema schema) {
GraphQL gql = GraphQL.newGraphQL(schema).build();
ExecutionResult result = gql.execute(IntrospectionQuery.INTROSPECTION_QUERY);
Assert.assertTrue(result.getErrors().size() == 0, "The schema has errors during Introspection");
return result.getData();
}
}