Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Expose ExplainEnum in the GQL schema #1204

Merged
merged 6 commits into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
}
}
2 changes: 2 additions & 0 deletions request/graphql/schema/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var (
},
})

// ExplainEnum is an enum for the @explain directive.
orpheuslummis marked this conversation as resolved.
Show resolved Hide resolved
ExplainEnum = gql.NewEnum(gql.EnumConfig{
Name: "ExplainType",
Values: gql.EnumValueConfigMap{
Expand All @@ -47,6 +48,7 @@ var (
},
})

// ExplainDirective @explain is used to explain the query.
orpheuslummis marked this conversation as resolved.
Show resolved Hide resolved
ExplainDirective *gql.Directive = gql.NewDirective(gql.DirectiveConfig{
Name: ExplainLabel,
Args: gql.FieldConfigArgument{
Expand Down
143 changes: 143 additions & 0 deletions tests/integration/schema/client_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
// 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"
)

const clientIntrospectionRequest string = `
orpheuslummis marked this conversation as resolved.
Show resolved Hide resolved
query IntrospectionQuery {
__schema {
queryType { name }
mutationType { name }
subscriptionType { name }
types {
...FullType
}
directives {
name
description
locations
args {
...InputValue
}
}
}
}

fragment FullType on __Type {
kind
name
description
fields(includeDeprecated: true) {
name
description
args {
...InputValue
}
type {
...TypeRef
}
isDeprecated
deprecationReason
}
inputFields {
...InputValue
}
interfaces {
...TypeRef
}
enumValues(includeDeprecated: true) {
name
description
isDeprecated
deprecationReason
}
possibleTypes {
...TypeRef
}
}

fragment InputValue on __InputValue {
name
description
type { ...TypeRef }
defaultValue
}

fragment TypeRef on __Type {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
}
}
}
}
}
}
}
}
`

// TestClientIntrospectionExplainTypeDefined tests that the introspection query returns a schema that
// defines the ExplainType enum.
func TestClientIntrospectionExplainTypeDefined(t *testing.T) {
test := RequestTestCase{
Schema: []string{},
IntrospectionRequest: clientIntrospectionRequest,
ContainsData: map[string]any{
"__schema": map[string]any{
"types": []any{
map[string]any{
"description": "",
"enumValues": []any{
map[string]any{
"deprecationReason": nil,
"description": "Simple explaination - dump of the plan graph.",
"isDeprecated": false,
"name": "simple",
},
},
"fields": nil,
orpheuslummis marked this conversation as resolved.
Show resolved Hide resolved
"inputFields": nil,
"interfaces": nil,
"kind": "ENUM",
"name": "ExplainType",
"possibleTypes": nil,
},
},
},
},
}

ExecuteRequestTestCase(t, test)
}