Skip to content

feat: allow int64 custom scalars#716

Merged
pavelnikolov merged 1 commit intomainfrom
issue-305
Mar 27, 2026
Merged

feat: allow int64 custom scalars#716
pavelnikolov merged 1 commit intomainfrom
issue-305

Conversation

@pavelnikolov
Copy link
Copy Markdown
Member

@pavelnikolov pavelnikolov commented Mar 27, 2026

Allow int64 custom scalars.

Closes #305

Copilot AI review requested due to automatic review settings March 27, 2026 06:26
@pavelnikolov pavelnikolov merged commit 63f5bb0 into main Mar 27, 2026
4 checks passed
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for passing large integer literals through to custom scalar unmarshaling by deserializing integer literals as int64 when they don’t fit in 32-bit, while preserving existing int32 behavior for 32-bit-range values.

Changes:

  • Update integer literal deserialization to parse as 64-bit and return int64 when outside 32-bit range.
  • Extend input coercion for int32 targets to also accept int64 values.
  • Add a regression test covering custom Int64 scalar input alongside built-in Int range validation behavior.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
ast/value.go Parses integer literals with 64-bit precision and returns int64 for out-of-32-bit-range values.
internal/exec/packer/packer.go Adds int64int32 coercion for packing into int32 Go targets.
issue_305_test.go Introduces test coverage for large integer literal behavior with a custom Int64 scalar and built-in Int validation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +20 to +25
value, ok := input.(int64)
if !ok {
return fmt.Errorf("Int64 expects int64 got %T", input)
}
u.Value = value
return nil
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test scalar’s UnmarshalGraphQL only accepts int64. With the current deserialization behavior, integer literals within 32-bit range are still provided as int32, so this scalar would reject valid Int64 inputs like custom(hash: 123). Consider accepting both int32 and int64 (casting int32 up) so the test scalar matches real-world usage and doesn’t encode an overly strict/unintuitive contract.

Suggested change
value, ok := input.(int64)
if !ok {
return fmt.Errorf("Int64 expects int64 got %T", input)
}
u.Value = value
return nil
switch v := input.(type) {
case int64:
u.Value = v
return nil
case int32:
u.Value = int64(v)
return nil
default:
return fmt.Errorf("Int64 expects int64 got %T", input)
}
Copilot uses AI. Check for mistakes.
Comment on lines +353 to +357
case int64:
if input < math.MinInt32 || input > math.MaxInt32 {
return nil, fmt.Errorf("not a 32-bit integer")
}
return int32(input), nil
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UnmarshalInput now explicitly accepts int64 for reflect.Int32, but integer literals can also deserialize to int64 when used in a GraphQL Float position (GraphQL allows Int literals for Float). The reflect.Float64 branch currently only coerces int32/int, so a large integer literal (or a variable value) arriving as int64 will fail with "incompatible type". Please add int64 handling in the reflect.Float64 coercion path (and consider tests for Float arguments with large integer literals).

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants