Skip to content

Commit d6fcf63

Browse files
committed
chore: add test verifying direct value resolving
This test verifies that values of arguments can be extracted directly from the AST when no variable remapping has taken place. Usually this is not the case in reality but if for whatever reason it will be reality one day, this method is proven to work with that.
1 parent a63ff06 commit d6fcf63

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

router/core/field_argument_visitor_test.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,3 +357,58 @@ func TestMapFieldArguments_InvalidValueLogsWarning(t *testing.T) {
357357
idArg := result.Get("user", "id")
358358
assert.Nil(t, idArg, "expected argument to be skipped due to error")
359359
}
360+
361+
func TestMapFieldArguments_InlineLiteralWithoutNormalization(t *testing.T) {
362+
// This test verifies that inline literal arguments are correctly extracted
363+
// via getArgValueFromDoc when normalization is skipped.
364+
// Normally, normalization converts inline literals to variables, but this test
365+
// exercises the code path for non-variable argument values.
366+
367+
schema := `
368+
type Query {
369+
user(id: ID!, active: Boolean!): User
370+
}
371+
type User {
372+
id: ID!
373+
}
374+
`
375+
376+
operation := `
377+
query {
378+
user(id: "inline-123", active: true) {
379+
id
380+
}
381+
}
382+
`
383+
384+
// Parse schema
385+
schemaDef, report := astparser.ParseGraphqlDocumentString(schema)
386+
require.False(t, report.HasErrors(), "failed to parse schema")
387+
err := asttransform.MergeDefinitionWithBaseSchema(&schemaDef)
388+
require.NoError(t, err)
389+
390+
// Parse operation WITHOUT normalization to keep inline literals as non-variable values
391+
op, report := astparser.ParseGraphqlDocumentString(operation)
392+
require.False(t, report.HasErrors(), "failed to parse operation")
393+
394+
// Parse empty variables (inline values are in the AST, not in variables)
395+
vars, err := astjson.ParseBytes([]byte(`{}`))
396+
require.NoError(t, err)
397+
398+
// Call mapFieldArguments - should extract values via getArgValueFromDoc
399+
result := mapFieldArguments(mapFieldArgumentsOpts{
400+
operation: &op,
401+
definition: &schemaDef,
402+
vars: vars,
403+
})
404+
405+
// Verify the string argument was correctly extracted
406+
idArg := result.Get("user", "id")
407+
require.NotNil(t, idArg, "expected 'id' argument to be accessible")
408+
assert.Equal(t, "inline-123", string(idArg.GetStringBytes()))
409+
410+
// Verify the boolean argument was correctly extracted
411+
activeArg := result.Get("user", "active")
412+
require.NotNil(t, activeArg, "expected 'active' argument to be accessible")
413+
assert.True(t, activeArg.GetBool())
414+
}

0 commit comments

Comments
 (0)