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

Provide defaultValue on input types in schema introspection #256

Merged
merged 3 commits into from
Feb 28, 2024
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
6 changes: 6 additions & 0 deletions executable_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,12 @@ func resolveField(ctx context.Context, schema *ast.Schema, field *ast.FieldDefin
result[f.Alias] = deprecated
case "deprecationReason":
result[f.Alias] = deprecatedReason
case "defaultValue":
if field.DefaultValue != nil {
result[f.Alias] = field.DefaultValue.String()
} else {
result[f.Alias] = nil
}
}
}

Expand Down
43 changes: 42 additions & 1 deletion execution_introspection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ func TestIntrospectionQuery(t *testing.T) {
movies: [Movie!]!
somethingRandom: MovieOrCinema
somePerson: Person
}

input CinemaInput {
name: String! = "SomeName"
}

type Mutation {
createCinema(input: CinemaInput!): Cinema
}`

// Make sure schema merging doesn't break introspection
Expand Down Expand Up @@ -454,10 +462,43 @@ func TestIntrospectionQuery(t *testing.T) {
"queryType": {
"name": "Query"
},
"mutationType": null,
"mutationType": {
"name": "Mutation"
},
"subscriptionType": null
}
}
`, string(resp.Data))
})

t.Run("input fields", func(t *testing.T) {
query := gqlparser.MustLoadQuery(es.MergedSchema, `{
__type(name: "CinemaInput") {
kind
name
inputFields {
name
defaultValue
}
}
}`)
ctx := testContextWithoutVariables(query.Operations[0])
resp := es.ExecuteQuery(ctx)

require.JSONEq(t, `
{
"__type": {
"kind": "INPUT_OBJECT",
"name": "CinemaInput",
"inputFields": [
{
"name": "name",
"defaultValue": "\"SomeName\""
}
]
}
}
`, string(resp.Data))
})

}