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

Centralized Content not available via JSON:API #16615

Closed
2 tasks
Tracked by #16780
timcosgrove opened this issue Jan 2, 2024 · 6 comments
Closed
2 tasks
Tracked by #16780

Centralized Content not available via JSON:API #16615

timcosgrove opened this issue Jan 2, 2024 · 6 comments

Comments

@timcosgrove
Copy link
Contributor

timcosgrove commented Jan 2, 2024

Requirements

We need Centralized Content nodes to return data via JSON:API so that we can render Centralized Content data.

Acceptance criteria

Preview Give feedback

Background & implementation details

Example query which does not show data (see any of the field_cc fields): https://prod.cms.va.gov/jsonapi/node/vamc_system_billing_insurance/cbeb033f-c091-4aba-8814-642ae0d389d9?resourceVersion=id%3A657971

See this open issue on Entity Field Fetch: https://www.drupal.org/project/entity_field_fetch/issues/3300098

Problem/Motivation
Entity Field Fetch fields return a computed value in a FieldFormatter, and there is also a plugin to provide a computed value to GraphQL. However, an entity with an EFF field that is output via JSON:API returns false for the value of that EFF field.

Steps to reproduce

  1. Set up a fresh Drupal install with Standard installation (should have Basic Page and Article node types).
  2. Add entity_field_fetch to your install. Enable it as well as JSON:API module.
  3. Create a Basic Page node. Take note of the title you give the node, and also the node id.
  4. Add an entity_field_fetch field to the Article content type. Point it at the nid from step 3, and the field title. Save.
  5. Create an Article node. The node edit form should contain the title from step 3. Save.
  6. View the Article node. The title from step 3 should be part of the output.
  7. View the Article node via JSON:API; /jsonapi/node/article should return the node.

Expected outcome: the JSON:API response contains the computed value of the EFF field.
Actual outcome: the JSON:API response contains false for the EFF field value.

Proposed resolution
entity_field_fetch most likely needs a TypedData Normalizer added to it. Information on this can be found in this Lullabot article: JSON:API 2.0 Has Been Released. It should be noted that Normalizers for custom fields are deprecated and should be avoided; see #2926507: Discourage @FieldType-level normalizers, encourage @DataType-level normalizers, to strengthen the API-First ecosystem

The EFF field should return the data structure of the field value it is pointed at. E.g. If that field is a text field, it should return a string; if that field is a rich text field, it should return the normal rich text data structure.

Care should be taken that, if the target field of the EFF is itself an entity reference, that that entity reference data is attached to the JSON:API response as expected; include as a query string argument should resolve as expected.

Implementation tasks

Preview Give feedback
@swirtSJW
Copy link
Contributor

swirtSJW commented Jan 4, 2024

This is what a fetched field (that is fetching a paragraph) looks like in GraphQL

          "fieldCcAboveTopOfPage": {
            "fetched": {
              "fieldWysiwyg": [
                {
                  "value": "<h2>Questions about copay balance</h2>\r\n\r\n<p>For questions about the copay balance of your VA health care bill, call us toll free at the number below. You won't need to pay any copays for X-rays, lab tests, preventative tests, and services like health screenings or immunizations.</p>\r\n",
                  "format": "rich_text",
                  "processed": "<h2>Questions about copay balance</h2>\n\n<p>For questions about the copay balance of your VA health care bill, call us toll free at the number below. You won't need to pay any copays for X-rays, lab tests, preventative tests, and services like health screenings or immunizations.</p>"
                }
              ]
            },
            "fetchedBundle": "wysiwyg",
            "targetField": null,
            "targetId": "109546",
            "targetType": "paragraph",
            "value": false
          }
        },

It looks to me like only the "value" property is being output by the JSONAPI results. The value, I think is there because it is a computed field.

@swirtSJW
Copy link
Contributor

swirtSJW commented Jan 4, 2024

I made a fair amount of discovery progress on this. I noted my findings in the d.o issue.

@alexfinnarn
Copy link
Contributor

The Dependabot PR is here: #16730

@alexfinnarn
Copy link
Contributor

I reviewed and approved of #16776

@alexfinnarn
Copy link
Contributor

PR merged so I think this can be closed, or maybe there is another QA step...

@timcosgrove
Copy link
Contributor Author

🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants