Khan / Khan/genqlient

InputObject field defaults are ignored/overridden

Open
#228 2 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Go
Stars
1.3k
Forks
143
Avg merge
4h 50m
Merged PRs (30d)
1

Description

**Describe the bug**
Hi geeks, Thanks for this amazing lib. I have the following graphql input with default fields

```gql
input FormInput {
hint: String
inputType: MwappFormInputType = TEXT
key: String = "form"
label: String = "Fill form"
maxLength: Int = 100
multiSubmission: Boolean = false
multiline: Boolean = false
obscure: Boolean = false
}

input SendMessageInput {
form: FormInput
}

type Mutation {
sendMessage(connectionId: ID!, input: SendMessageInput!): String!
}
```

Which I use in golang like
```go
mw.SendMessage(ConnectionId, mwapp.SendMessageInput{
Message: "Hi, Please tell us your name. \n you can write it below",
Form: &mwapp.FormInput{
Key: FormKeyName.String(),
},
})
```

As you can see above I just use one field `Key` and ignore the rest. So I expect the default graphql fields specified in schema to be used when send request. But they are sent like null too.

**To Reproduce**
Create mutation whose input have fields with default fields

**Expected behavior**
Default fields to be respected when. I believe having pointer with `omitempty` in the generated code will be the solution. But I don't know how to archive this

**genqlient version**
v0.5.0

**Additional context**
My genqclient.yaml is

```yaml
schema: schema.graphql
package: mwapp
operations:
- operations/*.graphql
generated: generated.go
use_struct_references : true
optional: pointer
bindings:
Timestamp:
type: time.Time
```

Any help on fixing this will be appreciated.

Contributor guide

Open the contributing guide

Research direction

Start with genqlient.yaml, schema.graphql, the operation under operations/*.graphql, and the resulting generated.go to trace how partially populated input structs are serialized. Reproduce the mutation with only Key set and verify that omitted fields are represented so the GraphQL schema defaults are applied rather than sending null values.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, graphql
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.