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

autobind on multiple packages has strange priority #845

Closed
moxar opened this issue Aug 28, 2019 · 6 comments
Closed

autobind on multiple packages has strange priority #845

moxar opened this issue Aug 28, 2019 · 6 comments
Labels
bug Something isn't working stale

Comments

@moxar
Copy link

moxar commented Aug 28, 2019

What happened?

When setting multiple autobind values, witch package containing a type with a similar name, there is no way to force priority.

What did you expect?

For each type, I expect gqlgen to do the binding with the first package in "autobind", and fallback to the second (and so on...) if the model is not found.

In my example:

  • I want gqlgen to use map ProjectFilter to graphqlapi.ProjectFilter
  • I want gqlgen to use map Project to httpapi.Project
  • I want gqlgen not to use httpapi.ProjectFilter

Minimal graphql.schema and models to reproduce

package httpapi

type Project struct{
  ID int `json:"id"`
  Name string `json:"name"`
}

type ProjectFilter struct{
  ID int `json:"id"`
}
package graphqlapi

type ProjectFilter struct{
  Name string `json:"name"`
}
type Project{
  id: Int!
  name: String!
}

type ProjectFilter{
  name: String!
}
# .gqlgen.yml
...
autobind:
  - graphqlapi
  - httpapi

versions

  • gqlgen v0.9.3
  • go version go1.12.5 linux/amd64
  • go modules
@vektah
Copy link
Collaborator

vektah commented Sep 30, 2019

fixed by #872

@vektah vektah closed this as completed Sep 30, 2019
@moxar
Copy link
Author

moxar commented Oct 2, 2019

Despite upgrading to v0.10.1, the issue is still there: I cannot force priority.
The consequence is that, if I don't map each model one...

  • gqlgen always maps the schema types to the httpapi types
  • the graphqlapi types that are declared are never used

@vektah
Copy link
Collaborator

vektah commented Oct 2, 2019

Sorry if that pr wasn't clear, you can now use the short package name as long as it's on the autobinl path eg "model.User"

@moxar
Copy link
Author

moxar commented Oct 2, 2019

I noticed indeed, but this does not solve the issue here.

What I aim to do is to use the autobind feature to avoid mapping each schema's type to a package's type. Here, I need...

  • ProjectFilter type (declared in the schema) mapped to graphqlapi.ProjectFilter
  • Project type (declared in schema too) mapped to httpapi.Project

To do so, I declared in the gqlgen.yml file:

autobind:
  - graphqlapi
  - httpapi

But when I do so, the graphqlapi types are never used: gqlgen uses httpapi package for both Project and ProjectFilter.

My current workaround consists in hand mapping each type, but I would want gqlgen to "first look into graphqlapi, if the model is missing, look into httpapi". But doing so, I end up with a lot of lines in the model mapping, which could be easily discarded.

Do you think that this could be solved ?

@vektah
Copy link
Collaborator

vektah commented Oct 2, 2019

Ok that sounds like a bug, it's meant to be a priority search path with the short package syntax to override when there is a type name collision

@vektah vektah reopened this Oct 2, 2019
@vektah vektah added the bug Something isn't working label Oct 2, 2019
@stale
Copy link

stale bot commented Dec 1, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Dec 1, 2019
@stale stale bot closed this as completed Dec 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working stale
Projects
None yet
Development

No branches or pull requests

2 participants