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

Clarify how to use GraphQLValues in Arguments #1077

Open
Denommus opened this issue Jun 28, 2022 · 7 comments
Open

Clarify how to use GraphQLValues in Arguments #1077

Denommus opened this issue Jun 28, 2022 · 7 comments
Labels
enhancement Improvement of existing features or bugfix

Comments

@Denommus
Copy link

Denommus commented Jun 28, 2022

Currently, I'm generating a dynamic GraphQL enum from the database (hence, I need access to my Context and TypeInfo), to be used as an input argument in one of my queries.

But right now I'm manually calling resolve from within the resolve_field_async in order to see whether my argument actually is a valid value for that Enum.

That happens because args.get only uses FromInputValue, it doesn't actually call resolve. And FromInputValue doesn't have access to Context and TypeInfo.

In conclusion, it would be useful if there would be a way of resolving Arguments, not only "getting" them.

@Denommus Denommus added the enhancement Improvement of existing features or bugfix label Jun 28, 2022
@tyranron
Copy link
Member

@Denommus yup, this is somewhat non-symmetrical. The juniper was designed considering possible dynamic GraphQL types, but was never really used/polished for them. With landing #1072 we'll have better core traits design allowing us working towards natural support of dynamic GraphQL types. And we'll inevitably hit the issue you've raised. Maybe not a 0.16 release goal, but will be definitely on our agenda. Thank you for clarifying this.

@Denommus
Copy link
Author

@tyranron besides manually calling resolve within resolve_field of its respective field, is there another way to check the type of an argument right now?

@tyranron
Copy link
Member

@Denommus what do you mean by "check the type of an argument"? An argument is given as an InputValue it has no type. GraphQLValue implementor decides which type to "deserialize" it into.

@Denommus
Copy link
Author

Denommus commented Jul 1, 2022

@tyranron I mean GraphQL Type. args.get::<Foo>("foo") does not check if the argument is a valid value as defined by the GraphQLType and GraphQLValue implementations on Foo.

@tyranron
Copy link
Member

tyranron commented Jul 1, 2022

@Denommus whether the type matches GraphQL schema is checked in a validation layer, before doing resolve.

@Denommus
Copy link
Author

Denommus commented Jul 1, 2022

@tyranron ah, but that validation layer doesn't check dynamic enums, is that it?

@tyranron
Copy link
Member

tyranron commented Jul 1, 2022

@Denommus yeah, it actually reuses FromInputValue implementation in the way:
|v| T::from_input_value(&v).is_ok()

I wonder whether we can specify Context and TypeInfo there. Seems that there is nothing wrong with it, as they're already present when validation happens, except the current machinery doesn't support it.

Oh... one edge case is that default values are validated on schema creation, where no Context is present. Need to think about it more.

Also, another pain point maybe possible persisted queries in future. Where the query will be validated with one Context, but executed (resolved) with another one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvement of existing features or bugfix
Projects
None yet
Development

No branches or pull requests

2 participants