Skip to content

Commit

Permalink
Replace *string with *graphql.ID
Browse files Browse the repository at this point in the history
  • Loading branch information
Slessi committed Dec 20, 2023
1 parent d90258e commit 53cca00
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
11 changes: 3 additions & 8 deletions nullable_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
// differentiate a value explicitly set to null from an omitted value.
// When the value is defined (either null or a value) Set is true.
type NullID struct {
Value *string
Value *ID
Set bool
}

Expand All @@ -24,13 +24,8 @@ func (s *NullID) UnmarshalGraphQL(input interface{}) error {
return nil
}

switch v := input.(type) {
case string:
s.Value = &v
return nil
default:
return fmt.Errorf("wrong type for ID: %T", v)
}
s.Value = new(ID)
return s.Value.UnmarshalGraphQL(input)
}

func (s *NullID) Nullable() {}
Expand Down
4 changes: 2 additions & 2 deletions nullable_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestNullID_UnmarshalGraphQL(t *testing.T) {
input interface{}
}

good := "1234"
good := graphql.ID("1234")
ref := graphql.NullID{
Value: &good,
Set: true,
Expand Down Expand Up @@ -72,7 +72,7 @@ func TestNullID_UnmarshalGraphQL(t *testing.T) {
{
name: "string",
args: args{
input: good,
input: string(good),
},
wantEq: ref,
},
Expand Down

0 comments on commit 53cca00

Please sign in to comment.