aribouius / jsonapi-react

A minimal JSON:API client and React hooks for fetching, updating, and caching remote data.
MIT License
149 stars 28 forks source link

Parse problem: only id is returned #35

Closed Steffi3rd closed 3 years ago

Steffi3rd commented 3 years ago

Context

I'm using Drupal with JSON API

Original Response :

{
  "jsonapi": {
    "version": "1.0",
    "meta": {
      "links": {
        "self": {
          "href": "http://jsonapi.org/format/1.0/"
        }
      }
    },
    "parsed": true
  },
  "data": [
    {
      "type": "news",
      "id": "b8bb5848-c531-41d9-a7fb-bc2a588491d6",
      "links": {
        "self": {
          "href": "http://localhost:8000/en/api/news/b8bb5848-c531-41d9-a7fb-bc2a588491d6?resourceVersion=id%3A13"
        }
      },
      "langcode": "en",
      "status": true,
      "title": "First",
      "created": "2021-05-21T14:44:30+00:00",
      "promote": false,
      "sticky": false,
      "metatag": null,
      "path": {
        "alias": "/first",
        "pid": 7,
        "langcode": "en"
      },
      "body": {
        "value": "",
        "format": "wysiwyg",
        "processed": "",
        "summary": "Summary : First News is an award-winning national UK newspaper for children, read at home or in school, with 2.2 million readers every week."
      },
      "meta_tags": null,
      "cities": [
        {
          "type": "city",
          "id": "c1acd0e6-802c-410b-9b05-d2dff366c558",
          "links": {
            "self": {
              "href": "http://localhost:8000/en/api/city/c1acd0e6-802c-410b-9b05-d2dff366c558"
            }
          },
          "langcode": "en",
          "status": true,
          "name": "Atlanta",
          "initials": "AT"
        }
      ],
      "disciplines": [
        {
          "type": "disciplines",
          "id": "472296ee-7880-4aab-a692-9d15100405c2"
        }
      ],
      "picture": {
        "type": "media--image",
        "id": "53709a20-6a2f-46e4-8f0f-a6e685909ac4"
      }
    }
  ],
  "meta": {
    "count": "1"
  },
  "links": {
    "self": {
      "href": "http://localhost:8000/api/news?include=cities"
    }
  }
}

Parsed response :

Only id is returned, with or without schema.

{
  data: [ { id: 'b8bb5848-c531-41d9-a7fb-bc2a588491d6' } ],
  jsonapi: { version: '1.0', meta: { links: [Object] }, parsed: true },
  meta: { count: '1' },
  links: {
    self: {
      href: 'http://localhost:8000/api/news?include=cities%2Cdisciplines'
    }
  }
}

Expected response :

I expect at least all fields to be returned, not only id

{
   "data": [
    {
      "type": "news",
      "id": "b8bb5848-c531-41d9-a7fb-bc2a588491d6",
      "links": {
        "self": {
          "href": "http://localhost:8000/en/api/news/b8bb5848-c531-41d9-a7fb-bc2a588491d6?resourceVersion=id%3A13"
        }
      },
      "langcode": "en",
      "status": true,
      "title": "First",
      "created": "2021-05-21T14:44:30+00:00",
      "promote": false,
      "sticky": false,
      "metatag": null,
      "path": {
        "alias": "/first",
        "pid": 7,
        "langcode": "en"
      },
      "body": {
        "value": "",
        "format": "wysiwyg",
        "processed": "",
        "summary": "Summary : First News is an award-winning national UK newspaper for children, read at home or in school, with 2.2 million readers every week."
      },
      "meta_tags": null,
      "cities": [
        {
          "type": "city",
          "id": "c1acd0e6-802c-410b-9b05-d2dff366c558",
          "links": {
            "self": {
              "href": "http://localhost:8000/en/api/city/c1acd0e6-802c-410b-9b05-d2dff366c558"
            }
          },
          "langcode": "en",
          "status": true,
          "name": "Atlanta",
          "initials": "AT"
        }
      ],
      "disciplines": [
        {
          "type": "disciplines",
          "id": "472296ee-7880-4aab-a692-9d15100405c2"
        }
      ],
      "picture": {
        "type": "media--image",
        "id": "53709a20-6a2f-46e4-8f0f-a6e685909ac4"
      }
    }
  ],
  jsonapi: { version: '1.0', meta: { links: [Object] }, parsed: true },
  meta: { count: '1' },
  links: {
    self: {
      href: 'http://localhost:8000/api/news?include=cities%2Cdisciplines'
    }
  }
}
Steffi3rd commented 3 years ago

Nevermind, someone from my team install a Drupal plugin named JSON:API Include : https://www.drupal.org/project/jsonapi_include

Both was in conflict.