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

Fix for nested fields backed by map or interface #854

Merged
merged 1 commit into from
Sep 24, 2019

Conversation

wabain
Copy link
Contributor

@wabain wabain commented Sep 8, 2019

In order to support distinguishing between null and missing values in GraphQL, gqlgen allows binding GraphQL types to map[string]interface{}. However, currently those types can't be embedded in generated models because model generation doesn't know about the special cases in type binding that make it work. Trying with master or v0.9.3 gives the error modelgen: package cannot be nil.

In order to fix this, this PR makes two changes:

  • Check for a type name of interface{} and map[string]interface{} in Binder.FindType. I added a variant function that takes responsibility for splitting the package and type names, but the old function is still there for backwards compatibility.

  • Extend the nilable type logic used in codegen for the executor to model field generation, so that an optional GraphQL value is bound to a field of type map[string]interface{} instead of *map[string]interface{}. In order to maintain backwards compatibility, this change only applies to the special cases where the map or interface type is specified directly in the gqlgen config, not to other Go types that have an underlying nilable type.

I have:

  • Added tests covering the bug / feature (see testing)
  • N/A Updated any relevant documentation (see docs)

@coveralls
Copy link

Coverage Status

Coverage increased (+0.04%) to 61.861% when pulling 8ed6ffc on wabain:nested-map-interface into 55b2144 on 99designs:master.

@vektah
Copy link
Collaborator

vektah commented Sep 24, 2019

This looks awesome, thanks for the PR.

@vektah vektah merged commit de8e559 into 99designs:master Sep 24, 2019
cgxxv pushed a commit to cgxxv/gqlgen that referenced this pull request Mar 25, 2022
Fix for nested fields backed by map or interface
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants