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

drupal_internal__*id is typed as string - should it be number? #686

Open
MartinDavi opened this issue Feb 15, 2024 · 2 comments
Open

drupal_internal__*id is typed as string - should it be number? #686

MartinDavi opened this issue Feb 15, 2024 · 2 comments
Labels
area: next-drupal bug Something isn't working

Comments

@MartinDavi
Copy link

Package containing the bug

next-drupal (NPM package)

Describe the bug

Hey, in types.ts we have:

export interface DrupalTaxonomyTerm extends JsonApiResourceWithPath {
  drupal_internal__tid: string
  changed: string
  default_langcode: boolean
  name: string
  description: string
  weight: number
}

But when I fetch terms from the jsonapi, drupal_internal__tid is a number. Same if it's a node id or what have you.

This just caused a tricky bug where I was trying to compare a string with a number which of course wasn't working.

I'm on 1.6.0.

@MartinDavi MartinDavi added bug Something isn't working triage A new issue that needs triage labels Feb 15, 2024
@JohnAlbin JohnAlbin added area: next-drupal and removed triage A new issue that needs triage labels Feb 22, 2024
@JohnAlbin JohnAlbin added this to the next-drupal 2.0.0 milestone Feb 22, 2024
@seoplague
Copy link

And description should it be an object ?
{ format: "basic_html", processed: "<p>Test description</p>" value: "<p>Test description</p>" }

@tjheffner
Copy link

Running into this with the Document media types. Note that DrupalNode and DrupalParagraph are have number as the type for the drupal_internal__*id, but DrupalMedia and DrupalFile have those as string. We are seeing them come through as number in our system.

export interface DrupalNode extends JsonApiResourceWithPath {
    drupal_internal__nid: number;
    drupal_internal__vid: number;
    changed: string;
    created: string;
    title: string;
    default_langcode: boolean;
    sticky: boolean;
}
export interface DrupalParagraph extends JsonApiResource {
    drupal_internal__id: number;
    drupal_internal__revision_id: number;
}
export interface DrupalBlock extends JsonApiResource {
    info: string;
}
export interface DrupalMedia extends JsonApiResource {
    drupal_internal__mid: string;
    drupal_internal__vid: string;
    changed: string;
    created: string;
    name: string;
}
export interface DrupalFile extends JsonApiResource {
    drupal_internal__fid: string;
    changed: string;
    created: string;
    filename: string;
    uri: {
        value: string;
        url: string;
    };
    filesize: number;
    filemime: string;
    resourceIdObjMeta?: DrupalFileMeta;
}
export interface DrupalFileMeta {
    alt?: string;
    title?: string;
    width: number;
    height: number;
}

A second issue is that the types for DrupalFIleMeta (via resourceIdObjMeta) are specific to images, but document files returned via JSON:API have a different resourceIdObjMeta surfaced.

images:

       "image": {
          "data": {
            "type": "file--file",
            "id": "e638fd17-9090-442b-a724-5113133b4d0f",
            "meta": {
              "alt": null,
              "title": null,
              "width": 456,
              "height": 304,
              "drupal_internal__target_id": 1
            }
          },

documents:

        "field_document": {
          "data": {
            "type": "file--file",
            "id": "b17bc9dd-a7ce-469a-9b9f-5550de367cea",
            "meta": {
              "display": true,
              "description": "",
              "drupal_internal__target_id": 10
            }
          },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: next-drupal bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants