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 5 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,
}
}
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
51 changes: 51 additions & 0 deletions tests/integration/schema/client_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// 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"
)

const clientIntrospectionRequest string = `
orpheuslummis marked this conversation as resolved.
Show resolved Hide resolved
query IntrospectionQuery {
__schema {
types {
kind
name
description
}
}
}
`

// 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": schemaTypes.ExplainEnum.Description(),
"kind": "ENUM",
"name": "ExplainType",
},
},
},
},
}

ExecuteRequestTestCase(t, test)
}