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

Depend on not passing field to the resolver unless in the query #147

Open
tsiege opened this issue Jul 1, 2020 · 3 comments
Open

Depend on not passing field to the resolver unless in the query #147

tsiege opened this issue Jul 1, 2020 · 3 comments
Labels
question Further information is requested

Comments

@tsiege
Copy link
Contributor

tsiege commented Jul 1, 2020

Maybe I'm misunderstanding the docs, but @depend(on: ["id"]) would mean to me that the id field should be in the parent argument no matter what, but it isn't unless its asked for as well in the graphql query.

@danielrearden
Copy link
Owner

That is working as intended, although it may not be well documented. If you have any columns you want to always select, you can specify them using the include argument on @model:

type SearchResult @model(table: "search_results", include: ["id", "type"])

@tsiege
Copy link
Contributor Author

tsiege commented Jul 1, 2020

Interesting, maybe it's the language in the docs, but I assumed that the following meant that if you say a field is dependent it will always be provided in the resolver when the field claiming the dependency is called. But it seems that if the dependency is also asked for in the query it is passed to the resolver of the dependent.

The @depend directive is used to indicate a field is not associated with a particular column, but still depends on one or more columns. If the field is requested, the specified columns will be included in the request and available to the field's resolver.

@danielrearden danielrearden added bug Something isn't working question Further information is requested and removed bug Something isn't working labels Jul 1, 2020
@danielrearden
Copy link
Owner

@tsiege Sorry, I think I misread your original post.

If field x includes @depend(on: "y"), then the resolver for x should be able to access the value for column y in its resolver through the first parameter passed to the resolver

  return parent.y + '!';
}

If parent.y is undefined, that's a bug.

There is one caveat here that could be tripping you up. @depend expects column names, not field names, and what's exposed in the resolver will match the provided column names (even if they happen to have a field associated with them). This allows you to depend on columns that aren't explicitly part of your model. In other words, if you wrote @depend(on: ["foo_bar"]), you'll access it as parent.foo_bar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants