Skip to content

Document recipes #560

@zth

Description

@zth

Force explicit type for union object

  • RescriptRelay emits all union selections as inline records on the union type itself
  • This can be problematic in cases where you want to return the object inside of the union directly. You can't, because it's an inline record and that record definition can't be used directly
  • Work around it by using an inline spread with an @alias, to force the selection into its own field (and therefore get its own type)

Before:

// session = User({...inline record})
module UserQuery = %relay(`
  query UserQuery {
    session {
      user {
        ... on User {
          id
          firstName
          lastName
          displayName
          email
        }
      }
    }
  }
`)

After:

// session = User({user: type_user})
module UserQuery = %relay(`
  query UserQuery {
    session {
      user {
        ... on User {
          ... @alias(as: "user") {
            id
            firstName
            lastName
            displayName
            email
          }
        }
      }
    }
  }
`)

Delete several items from a connection at once

  • Response has list of items with id -> use with @deleteNode
  • If not, write an imperative updater using ConnectionHandler that removes them by hand. Simple since it's only IDs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions