Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose raw args (a.k.a. packed args) through SelectedField #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions exec/selected/selected.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,18 @@ func (sf *SchemaField) ToSelectedField() *types.SelectedField {
if sf == nil {
return nil
}
return &types.SelectedField{
res := &types.SelectedField{
Name: sf.Name,
TypeName: sf.Field.Type.String(),
Alias: sf.Alias,
Fields: selsToSelectedFields(sf.Sels),
Args: sf.Args,
ArgsMap: sf.Args,
Directives: append(sf.Directives, sf.Field.Directives...),
}
if sf.PackedArgs.IsValid() {
res.Args = sf.PackedArgs.Interface()
Copy link
Member

Choose a reason for hiding this comment

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

can you please elaborate on how it's supposed to be used?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The caller of the field selection knows the argument type used in the place where the lookup is performed. Therefore they can cast it to that type and do whatever they like.

}
return res
}

func selsToSelectedFields(sels []Selection) (res []*types.SelectedField) {
Expand Down
2 changes: 1 addition & 1 deletion selected_fields_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (r *nestedAliasesArgsDirectivesQueryResolver) Test(ctx context.Context) nes
if aDir == nil {
failWithError(r.T, "testFieldDirective doesn't exist on a")
}
aArgValue, ok := a.Args["value"]
aArgValue, ok := a.ArgsMap["value"]
if !ok {
failWithError(r.T, "value argument on a doesn't exist")
}
Expand Down
3 changes: 2 additions & 1 deletion types/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ type SelectedField struct {
TypeName string
Alias string // equal to Name if alias is not provided
Directives DirectiveList
Args map[string]interface{}
Args interface{}
ArgsMap map[string]interface{}
Fields []*SelectedField
AssertedTypeName string // non-empty for field selections on union fields
}
Expand Down