Skip to content

@bsRecord with two different types of the same structure #82

Closed
@andrewlinfoot

Description

@andrewlinfoot

Hey all, I'm working on converting some of our app queries from Js.t to @bsRecord syntax. I'm running into and issue where @bsRecord doesn't see to be mapping to the right record type when I have two fields of the same name/structure.

Here is the code:

type user = {
  id: string,
  firstName: option(string),
  lastName: option(string),
};

type actor = {user: option(user)};

type target = {user};

type activity = {
  id: string,
  createdAt: Js.Date.t,
  type_: [ | `USER_POST | `CALENDLY | `APPLICATION],
  body: option(string),
  actor: option(actor),
  target,
};

module Fragment = [%graphql
  {|
  fragment Activity on Activity @bsRecord {
    id
        createdAt  @bsDecoder(fn: "Decoders.dateDecoder")
        type_: type
        body
        actor @bsRecord {
          user @bsRecord {
            id
            firstName
            lastName
          }
        }

        target @bsRecord {
          user @bsRecord  {
            id
            firstName
            lastName
          }
        }
  }
  |}
];

The code compiles fine if I only want the actor or target fields individually but if I try to have both, I get the following error:

  26 ┆ body
  27 ┆ actor @bsRecord {
  28 ┆   user @bsRecord {
  29 ┆     id
  30 ┆     firstName
  31 ┆     lastName
  32 ┆   }
  33 ┆ }
  34 ┆

  This has type:
    option(user)
  But somewhere wanted:
    user

It doesn't seem to pick up the actor should have an optional user and target should have a non-optional user.

Here are the graphql type defs:

  type ActivityActor {
    user: User
  }

  type ActivityTarget {
    user: User!
  }

  type Activity {
    id: ID!
    createdAt: Date!
    type: ActivityType!
    body: String
    actor: ActivityActor
    target: ActivityTarget!
  }

Would love any help on this one. Once again, not sure if this an issue with my syntax or an actual bug? 😅

Thanks a ton!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions