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

Can't figure out how to use field_name/2 for sparse fieldsets #156

Closed
kbaird opened this issue Jan 9, 2019 · 2 comments
Closed

Can't figure out how to use field_name/2 for sparse fieldsets #156

kbaird opened this issue Jan 9, 2019 · 2 comments

Comments

@kbaird
Copy link
Contributor

kbaird commented Jan 9, 2019

I've been reading the docs, and found You can define custom fields or override current fields by defining inside the view function field_name/2 that takes data and conn as arguments. at https://hexdocs.pm/jsonapi/JSONAPI.View.html#module-fields

I've tried defining field_name/2 on my pertinent view module, but it seems to be ignored when fields/0 is present, and fields/0 being absent produces the error from https://github.com/jeregrine/jsonapi/blob/master/lib/jsonapi/view.ex#L138.

Is there any guidance I'm missing on how to comply with https://jsonapi.org/format/#fetching-sparse-fieldsets?

@kbaird
Copy link
Contributor Author

kbaird commented Jan 10, 2019

Oh, I see. field_name is a meta-variable. So if you have a field called foobar, you need to define def foobar(data, conn), do: ... in your view module.

That said, I still don't see how to truncate the list of fields based on the request. I don't want nil (or some otherwise modified value) for a given field name - I want the field name to be absent entirely, which seems to be what the spec prescribes. And fields/0 not taking in the conn seems to make it an all-or-nothing affair.

@jherdman
Copy link
Contributor

@jeregrine is this your intention in #120?

jherdman added a commit to jherdman/jsonapi that referenced this issue Jan 31, 2019
Whilst the `QueryParser` was correctly identifying requested fieldsets,
nothing was done to actually support this.

This change prunes returned fields to those requested should it be the
case.

Note that this change also includes a few more typespecs for functions I
touched or read.

Resolves beam-community#120
Closes beam-community#156
jherdman added a commit to jherdman/jsonapi that referenced this issue Feb 3, 2019
Whilst the `QueryParser` was correctly identifying requested fieldsets,
nothing was done to actually support this.

This change prunes returned fields to those requested should it be the
case.

Note that this change also includes a few more typespecs for functions I
touched or read.

Resolves beam-community#120
Closes beam-community#156
jherdman added a commit to jherdman/jsonapi that referenced this issue Feb 6, 2019
Whilst the `QueryParser` was correctly identifying requested fieldsets,
nothing was done to actually support this.

This change prunes returned fields to those requested should it be the
case.

Note that this change also includes a few more typespecs for functions I
touched or read.

Resolves beam-community#120
Closes beam-community#156
jherdman added a commit to jherdman/jsonapi that referenced this issue Feb 12, 2019
Whilst the `QueryParser` was correctly identifying requested fieldsets,
nothing was done to actually support this.

This change prunes returned fields to those requested should it be the
case.

Note that this change also includes a few more typespecs for functions I
touched or read.

Resolves beam-community#120
Closes beam-community#156
jherdman added a commit to jherdman/jsonapi that referenced this issue Feb 12, 2019
Whilst the `QueryParser` was correctly identifying requested fieldsets,
nothing was done to actually support this.

This change prunes returned fields to those requested should it be the
case.

Note that this change also includes a few more typespecs for functions I
touched or read.

Resolves beam-community#120
Closes beam-community#156
jherdman added a commit to jherdman/jsonapi that referenced this issue Feb 13, 2019
Whilst the `QueryParser` was correctly identifying requested fieldsets,
nothing was done to actually support this.

This change prunes returned fields to those requested should it be the
case.

Note that this change also includes a few more typespecs for functions I
touched or read.

Resolves beam-community#120
Closes beam-community#156
jherdman added a commit to jherdman/jsonapi that referenced this issue Feb 13, 2019
Whilst the `QueryParser` was correctly identifying requested fieldsets,
nothing was done to actually support this.

This change prunes returned fields to those requested should it be the
case.

Note that this change also includes a few more typespecs for functions I
touched or read.

Resolves beam-community#120
Closes beam-community#156
jherdman added a commit to jherdman/jsonapi that referenced this issue Feb 13, 2019
Whilst the `QueryParser` was correctly identifying requested fieldsets,
nothing was done to actually support this.

This change prunes returned fields to those requested should it be the
case.

Note that this change also includes a few more typespecs for functions I
touched or read.

Resolves beam-community#120
Closes beam-community#156
jherdman added a commit to jherdman/jsonapi that referenced this issue Feb 17, 2019
Whilst the `QueryParser` was correctly identifying requested fieldsets,
nothing was done to actually support this.

This change prunes returned fields to those requested should it be the
case.

Note that this change also includes a few more typespecs for functions I
touched or read.

Resolves beam-community#120
Closes beam-community#156
jherdman added a commit to jherdman/jsonapi that referenced this issue Feb 17, 2019
Whilst the `QueryParser` was correctly identifying requested fieldsets,
nothing was done to actually support this.

This change prunes returned fields to those requested should it be the
case.

Note that this change also includes a few more typespecs for functions I
touched or read.

Resolves beam-community#120
Closes beam-community#156
jherdman added a commit to jherdman/jsonapi that referenced this issue Feb 18, 2019
Whilst the `QueryParser` was correctly identifying requested fieldsets,
nothing was done to actually support this.

This change prunes returned fields to those requested should it be the
case.

Note that this change also includes a few more typespecs for functions I
touched or read.

Resolves beam-community#120
Closes beam-community#156
jherdman added a commit to jherdman/jsonapi that referenced this issue Feb 21, 2019
Whilst the `QueryParser` was correctly identifying requested fieldsets,
nothing was done to actually support this.

This change prunes returned fields to those requested should it be the
case.

Note that this change also includes a few more typespecs for functions I
touched or read.

Resolves beam-community#120
Closes beam-community#156
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

No branches or pull requests

2 participants