Skip to content

Commit 8cf6855

Browse files
fix: Expose ExplainEnum in the GQL schema (#1204)
Adds ExplainEnum to the GQL schema. It fixes the introspection query error with Altair and GraphiQL. Adds a test for the enum existence in resulting response schema.
1 parent 0077635 commit 8cf6855

File tree

3 files changed

+55
-2
lines changed

3 files changed

+55
-2
lines changed

request/graphql/schema/manager.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,5 +160,7 @@ func defaultTypes() []gql.Type {
160160
schemaTypes.CommitLinkObject,
161161
schemaTypes.CommitObject,
162162
schemaTypes.DeltaObject,
163+
164+
schemaTypes.ExplainEnum,
163165
}
164166
}

request/graphql/schema/types/types.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ var (
3838
})
3939

4040
ExplainEnum = gql.NewEnum(gql.EnumConfig{
41-
Name: "ExplainType",
41+
Name: "ExplainType",
42+
Description: "ExplainType is an enum selecting the type of explanation done by the @explain directive.",
4243
Values: gql.EnumValueConfigMap{
4344
ExplainArgSimple: &gql.EnumValueConfig{
4445
Value: ExplainArgSimple,
@@ -48,7 +49,8 @@ var (
4849
})
4950

5051
ExplainDirective *gql.Directive = gql.NewDirective(gql.DirectiveConfig{
51-
Name: ExplainLabel,
52+
Name: ExplainLabel,
53+
Description: "@explain is a directive that can be used to explain the query.",
5254
Args: gql.FieldConfigArgument{
5355
ExplainArgNameType: &gql.ArgumentConfig{
5456
Type: ExplainEnum,
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright 2022 Democratized Data Foundation
2+
//
3+
// Use of this software is governed by the Business Source License
4+
// included in the file licenses/BSL.txt.
5+
//
6+
// As of the Change Date specified in that file, in accordance with
7+
// the Business Source License, use of this software will be governed
8+
// by the Apache License, Version 2.0, included in the file
9+
// licenses/APL.txt.
10+
11+
package schema
12+
13+
import (
14+
"testing"
15+
16+
schemaTypes "github.com/sourcenetwork/defradb/request/graphql/schema/types"
17+
)
18+
19+
// TestIntrospectionExplainTypeDefined tests that the introspection query returns a schema that
20+
// defines the ExplainType enum.
21+
func TestIntrospectionExplainTypeDefined(t *testing.T) {
22+
test := RequestTestCase{
23+
Schema: []string{},
24+
IntrospectionRequest: `
25+
query IntrospectionQuery {
26+
__schema {
27+
types {
28+
kind
29+
name
30+
description
31+
}
32+
}
33+
}
34+
`,
35+
ContainsData: map[string]any{
36+
"__schema": map[string]any{
37+
"types": []any{
38+
map[string]any{
39+
"description": schemaTypes.ExplainEnum.Description(),
40+
"kind": "ENUM",
41+
"name": "ExplainType",
42+
},
43+
},
44+
},
45+
},
46+
}
47+
48+
ExecuteRequestTestCase(t, test)
49+
}

0 commit comments

Comments
 (0)