Skip to content

Commit

Permalink
feat: override default Int32 to Int64 scalar (#2)
Browse files Browse the repository at this point in the history
This PR takes its roots from: 7ff025f#diff-c97da2e4c49f2df9f25610f8474b7b2a69446d1256cd30bb5a114118b82d04e6.

We support JavaScript and its wacky numbers, seems like we'd need to limit ourselves to 9007199254740991: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER

The library was already taking into account the Int64 scalar, it was reverted to comply with `graphql-js`

Signed-off-by: grouville <guillaume@dagger.io>
grouville authored Jun 1, 2023
1 parent 24d5e47 commit 137fc3a
Showing 10 changed files with 181 additions and 181 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ on:
jobs:
go:
name: go
runs-on: ubuntu-22.04-16c-64g-600gb
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
with:
18 changes: 9 additions & 9 deletions enum_type_test.go
Original file line number Diff line number Diff line change
@@ -14,13 +14,13 @@ var enumTypeTestColorType = graphql.NewEnum(graphql.EnumConfig{
Name: "Color",
Values: graphql.EnumValueConfigMap{
"RED": &graphql.EnumValueConfig{
Value: 0,
Value: int64(0),
},
"GREEN": &graphql.EnumValueConfig{
Value: 1,
Value: int64(1),
},
"BLUE": &graphql.EnumValueConfig{
Value: 2,
Value: int64(2),
},
},
})
@@ -147,7 +147,7 @@ func TestTypeSystem_EnumValues_AcceptsEnumLiteralsAsInput(t *testing.T) {
query := "{ colorInt(fromEnum: GREEN) }"
expected := &graphql.Result{
Data: map[string]interface{}{
"colorInt": 1,
"colorInt": int64(1),
},
}
result := executeEnumTypeTest(t, query)
@@ -360,7 +360,7 @@ func TestTypeSystem_EnumValues_EnumValueMayHaveAnInternalValueOfZero(t *testing.
expected := &graphql.Result{
Data: map[string]interface{}{
"colorEnum": "RED",
"colorInt": 0,
"colorInt": int64(0),
},
}
result := executeEnumTypeTest(t, query)
@@ -404,10 +404,10 @@ func TestTypeSystem_EnumValues_EnumValueMayBePointer(t *testing.T) {
},
}),
Resolve: func(_ graphql.ResolveParams) (interface{}, error) {
one := 1
one := int64(1)
return struct {
Color *int `graphql:"color"`
Foo *int `graphql:"foo"`
Color *int64 `graphql:"color"`
Foo *int64 `graphql:"foo"`
}{&one, &one}, nil
},
},
@@ -419,7 +419,7 @@ func TestTypeSystem_EnumValues_EnumValueMayBePointer(t *testing.T) {
Data: map[string]interface{}{
"query": map[string]interface{}{
"color": "GREEN",
"foo": 1}}}
"foo": int64(1)}}}
result := g(t, graphql.Params{
Schema: enumTypeTestSchema,
RequestString: query,
20 changes: 10 additions & 10 deletions executor_resolve_test.go
Original file line number Diff line number Diff line change
@@ -120,7 +120,7 @@ func TestExecutesResolveFunction_UsesProvidedResolveFunction_SourceIsStruct_With
// For structs without JSON tags, it will map to upper-cased exported field names
type SubObjectWithoutJSONTags struct {
Str string
Int int
Int int64
}

schema := testSchema(t, &graphql.Field{
@@ -138,7 +138,7 @@ func TestExecutesResolveFunction_UsesProvidedResolveFunction_SourceIsStruct_With
},
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
aStr, _ := p.Args["aStr"].(string)
aInt, _ := p.Args["aInt"].(int)
aInt, _ := p.Args["aInt"].(int64)
return &SubObjectWithoutJSONTags{
Str: aStr,
Int: aInt,
@@ -149,7 +149,7 @@ func TestExecutesResolveFunction_UsesProvidedResolveFunction_SourceIsStruct_With
expected := map[string]interface{}{
"test": map[string]interface{}{
"Str": "",
"Int": 0,
"Int": int64(0),
},
}
result := graphql.Do(graphql.Params{
@@ -164,7 +164,7 @@ func TestExecutesResolveFunction_UsesProvidedResolveFunction_SourceIsStruct_With
expected = map[string]interface{}{
"test": map[string]interface{}{
"Str": "String!",
"Int": 0,
"Int": int64(0),
},
}
result = graphql.Do(graphql.Params{
@@ -178,7 +178,7 @@ func TestExecutesResolveFunction_UsesProvidedResolveFunction_SourceIsStruct_With
expected = map[string]interface{}{
"test": map[string]interface{}{
"Str": "String!",
"Int": -123,
"Int": int64(-123),
},
}
result = graphql.Do(graphql.Params{
@@ -196,7 +196,7 @@ func TestExecutesResolveFunction_UsesProvidedResolveFunction_SourceIsStruct_With
type SubObjectWithJSONTags struct {
OtherField string `json:""`
Str string `json:"str"`
Int int `json:"int"`
Int int64 `json:"int"`
}

schema := testSchema(t, &graphql.Field{
@@ -214,7 +214,7 @@ func TestExecutesResolveFunction_UsesProvidedResolveFunction_SourceIsStruct_With
},
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
aStr, _ := p.Args["aStr"].(string)
aInt, _ := p.Args["aInt"].(int)
aInt, _ := p.Args["aInt"].(int64)
return &SubObjectWithJSONTags{
Str: aStr,
Int: aInt,
@@ -225,7 +225,7 @@ func TestExecutesResolveFunction_UsesProvidedResolveFunction_SourceIsStruct_With
expected := map[string]interface{}{
"test": map[string]interface{}{
"str": "",
"int": 0,
"int": int64(0),
},
}
result := graphql.Do(graphql.Params{
@@ -240,7 +240,7 @@ func TestExecutesResolveFunction_UsesProvidedResolveFunction_SourceIsStruct_With
expected = map[string]interface{}{
"test": map[string]interface{}{
"str": "String!",
"int": 0,
"int": int64(0),
},
}
result = graphql.Do(graphql.Params{
@@ -254,7 +254,7 @@ func TestExecutesResolveFunction_UsesProvidedResolveFunction_SourceIsStruct_With
expected = map[string]interface{}{
"test": map[string]interface{}{
"str": "String!",
"int": -123,
"int": int64(-123),
},
}
result = graphql.Do(graphql.Params{
4 changes: 2 additions & 2 deletions executor_schema_test.go
Original file line number Diff line number Diff line change
@@ -235,8 +235,8 @@ func TestExecutesUsingAComplexSchema(t *testing.T) {
"name": "John Smith",
"pic": map[string]interface{}{
"url": "cdn://123",
"width": 640,
"height": 480,
"width": int64(640),
"height": int64(480),
},
"recentArticle": map[string]interface{}{
"id": "1",
6 changes: 3 additions & 3 deletions executor_test.go
Original file line number Diff line number Diff line change
@@ -113,11 +113,11 @@ func TestExecutesArbitraryCode(t *testing.T) {
return nil, nil
}
// get and type assert argument
sizeArg, ok := p.Args["size"].(int)
sizeArg, ok := p.Args["size"].(int64)
if !ok {
return nil, nil
}
return picResolver(sizeArg), nil
return picResolver(int(sizeArg)), nil
}
dataType := graphql.NewObject(graphql.ObjectConfig{
Name: "DataType",
@@ -455,7 +455,7 @@ func TestCorrectlyThreadsArguments(t *testing.T) {
t.Fatalf("wrong result, unexpected errors: %v", result.Errors)
}

expectedNum := 123
expectedNum := int64(123)
expectedString := "foo"
if resolvedArgs["numArg"] != expectedNum {
t.Fatalf("Expected args.numArg to equal `%v`, got `%v`", expectedNum, resolvedArgs["numArg"])
40 changes: 20 additions & 20 deletions lists_test.go
Original file line number Diff line number Diff line change
@@ -65,7 +65,7 @@ func TestLists_ListOfNullableObjects_ContainsValues(t *testing.T) {
Data: map[string]interface{}{
"nest": map[string]interface{}{
"test": []interface{}{
1, 2,
int64(1), int64(2),
},
},
},
@@ -81,7 +81,7 @@ func TestLists_ListOfNullableObjects_ContainsNull(t *testing.T) {
Data: map[string]interface{}{
"nest": map[string]interface{}{
"test": []interface{}{
1, nil, 2,
int64(1), nil, int64(2),
},
},
},
@@ -115,7 +115,7 @@ func TestLists_ListOfNullableFunc_ContainsValues(t *testing.T) {
Data: map[string]interface{}{
"nest": map[string]interface{}{
"test": []interface{}{
1, 2,
int64(1), int64(2),
},
},
},
@@ -129,14 +129,14 @@ func TestLists_ListOfNullableFunc_ContainsNull(t *testing.T) {
// Note that its uses the expected signature `func() interface{} {...}`
data := func() interface{} {
return []interface{}{
1, nil, 2,
int64(1), nil, int64(2),
}
}
expected := &graphql.Result{
Data: map[string]interface{}{
"nest": map[string]interface{}{
"test": []interface{}{
1, nil, 2,
int64(1), nil, int64(2),
},
},
},
@@ -179,7 +179,7 @@ func TestLists_ListOfNullableArrayOfFuncContainsValues(t *testing.T) {
Data: map[string]interface{}{
"nest": map[string]interface{}{
"test": []interface{}{
1, 2,
int64(1), int64(2),
},
},
},
@@ -206,7 +206,7 @@ func TestLists_ListOfNullableArrayOfFuncContainsNulls(t *testing.T) {
Data: map[string]interface{}{
"nest": map[string]interface{}{
"test": []interface{}{
1, nil, 2,
int64(1), nil, int64(2),
},
},
},
@@ -224,7 +224,7 @@ func TestLists_NonNullListOfNullableObjectsContainsValues(t *testing.T) {
Data: map[string]interface{}{
"nest": map[string]interface{}{
"test": []interface{}{
1, 2,
int64(1), int64(2),
},
},
},
@@ -240,7 +240,7 @@ func TestLists_NonNullListOfNullableObjectsContainsNull(t *testing.T) {
Data: map[string]interface{}{
"nest": map[string]interface{}{
"test": []interface{}{
1, nil, 2,
int64(1), nil, int64(2),
},
},
},
@@ -287,7 +287,7 @@ func TestLists_NonNullListOfNullableFunc_ContainsValues(t *testing.T) {
Data: map[string]interface{}{
"nest": map[string]interface{}{
"test": []interface{}{
1, 2,
int64(1), int64(2),
},
},
},
@@ -308,7 +308,7 @@ func TestLists_NonNullListOfNullableFunc_ContainsNull(t *testing.T) {
Data: map[string]interface{}{
"nest": map[string]interface{}{
"test": []interface{}{
1, nil, 2,
int64(1), nil, int64(2),
},
},
},
@@ -364,7 +364,7 @@ func TestLists_NonNullListOfNullableArrayOfFunc_ContainsValues(t *testing.T) {
Data: map[string]interface{}{
"nest": map[string]interface{}{
"test": []interface{}{
1, 2,
int64(1), int64(2),
},
},
},
@@ -391,7 +391,7 @@ func TestLists_NonNullListOfNullableArrayOfFunc_ContainsNulls(t *testing.T) {
Data: map[string]interface{}{
"nest": map[string]interface{}{
"test": []interface{}{
1, nil, 2,
int64(1), nil, int64(2),
},
},
},
@@ -409,7 +409,7 @@ func TestLists_NullableListOfNonNullObjects_ContainsValues(t *testing.T) {
Data: map[string]interface{}{
"nest": map[string]interface{}{
"test": []interface{}{
1, 2,
int64(1), int64(2),
},
},
},
@@ -474,7 +474,7 @@ func TestLists_NullableListOfNonNullFunc_ContainsValues(t *testing.T) {
Data: map[string]interface{}{
"nest": map[string]interface{}{
"test": []interface{}{
1, 2,
int64(1), int64(2),
},
},
},
@@ -552,7 +552,7 @@ func TestLists_NullableListOfNonNullArrayOfFunc_ContainsValues(t *testing.T) {
Data: map[string]interface{}{
"nest": map[string]interface{}{
"test": []interface{}{
1, 2,
int64(1), int64(2),
},
},
},
@@ -618,7 +618,7 @@ func TestLists_NonNullListOfNonNullObjects_ContainsValues(t *testing.T) {
Data: map[string]interface{}{
"nest": map[string]interface{}{
"test": []interface{}{
1, 2,
int64(1), int64(2),
},
},
},
@@ -693,7 +693,7 @@ func TestLists_NonNullListOfNonNullFunc_ContainsValues(t *testing.T) {
Data: map[string]interface{}{
"nest": map[string]interface{}{
"test": []interface{}{
1, 2,
int64(1), int64(2),
},
},
},
@@ -782,7 +782,7 @@ func TestLists_NonNullListOfNonNullArrayOfFunc_ContainsValues(t *testing.T) {
Data: map[string]interface{}{
"nest": map[string]interface{}{
"test": []interface{}{
1, 2,
int64(1), int64(2),
},
},
},
@@ -873,7 +873,7 @@ func TestLists_ArrayOfNullableObjects_ContainsValues(t *testing.T) {
Data: map[string]interface{}{
"nest": map[string]interface{}{
"test": []interface{}{
1, 2,
int64(1), int64(2),
},
},
},
Loading
Oops, something went wrong.

0 comments on commit 137fc3a

Please sign in to comment.