Skip to content

Commit

Permalink
fix: Expose ExplainEnum in the GQL schema (#1204)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
orpheuslummis authored Mar 21, 2023
1 parent 0077635 commit 8cf6855
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
2 changes: 2 additions & 0 deletions request/graphql/schema/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,5 +160,7 @@ func defaultTypes() []gql.Type {
schemaTypes.CommitLinkObject,
schemaTypes.CommitObject,
schemaTypes.DeltaObject,

schemaTypes.ExplainEnum,
}
}
6 changes: 4 additions & 2 deletions request/graphql/schema/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ var (
})

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

ExplainDirective *gql.Directive = gql.NewDirective(gql.DirectiveConfig{
Name: ExplainLabel,
Name: ExplainLabel,
Description: "@explain is a directive that can be used to explain the query.",
Args: gql.FieldConfigArgument{
ExplainArgNameType: &gql.ArgumentConfig{
Type: ExplainEnum,
Expand Down
49 changes: 49 additions & 0 deletions tests/integration/schema/client_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright 2022 Democratized Data Foundation
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

package schema

import (
"testing"

schemaTypes "github.com/sourcenetwork/defradb/request/graphql/schema/types"
)

// TestIntrospectionExplainTypeDefined tests that the introspection query returns a schema that
// defines the ExplainType enum.
func TestIntrospectionExplainTypeDefined(t *testing.T) {
test := RequestTestCase{
Schema: []string{},
IntrospectionRequest: `
query IntrospectionQuery {
__schema {
types {
kind
name
description
}
}
}
`,
ContainsData: map[string]any{
"__schema": map[string]any{
"types": []any{
map[string]any{
"description": schemaTypes.ExplainEnum.Description(),
"kind": "ENUM",
"name": "ExplainType",
},
},
},
},
}

ExecuteRequestTestCase(t, test)
}

0 comments on commit 8cf6855

Please sign in to comment.