扩展@connection节点并在本地存储中访问它

问题描述

我正在尝试使用标志字段扩展@connection的节点,我将在单击时更新该字段:

graphql中的连接:

type Me implements Node {
  id: ID!
  giftRecipientsConnection(
    query: String!

    after: String
    first: Int
    before: String
    last: Int
  ): GiftRecipientConnection
}

"An edge in a connection."
type GiftRecipientEdge {
  "The item at the end of the edge"
  node: GiftRecipient

  "A cursor for use in pagination"
  cursor: String!
}

"A GiftRecipient"
type GiftRecipient {
  platform: Platform!
  platformIcon: Image!
  followers: Int!
  userName: String!
  avatar: Image!
  avatarBackground: Image!
  isGiftable: Boolean!
  hashId: String!
}

客户端架构:

extend type GiftRecipient {
  isSelected: Boolean
}

那是我的组件(查询可能并不理想,因为我仍在尝试,但它可以工作):

export const GiftRecipientsFragmentContainer = createPaginationContainer(
  GiftRecipients,{
    giftRecipientsMe: graphql`
      fragment GiftRecipients_giftRecipientsMe on Me
        @argumentDefinitions(
          query: { type: "String",defaultValue: "*" }
          cursor: { type: "String",defaultValue: null }
          first: { type: "Int",defaultValue: 50 }
        ) {
        id
        giftRecipientsConnection(query: $query,first: $first,after: $cursor)
          @connection(
            key: "GiftRecipientsMe_giftRecipientsConnection"
            filters: ["query"]
          ) {
          pageInfo {
            hasNextPage
            hasPreviousPage
            endCursor
            startCursor
          }
          edges {
            node {
              isGiftable
              isSelected
              platform
              platformIcon {
                url
              }
              followers
              userName
              hashId
              avatar {
                url
              }
              avatarBackground {
                url
              }
            }
          }
        }
      }
    `,},{
    direction: "forward",getConnectionFromProps(props) {
      return props.giftRecipientsMe.giftRecipientsConnection
    },getVariables(_,__,fragmentVariables) {
      return {
        ...fragmentVariables,}
    },query: graphql`
      query GiftRecipientsPaginationQuery(
        $query: String!
        $first: Int!
        $cursor: String!
      ) {
        me {
          ...GiftRecipients_giftRecipientsMe
            @arguments(query: $query,cursor: $cursor)
        }
      }
    `,}
)

在我的组件中,我想像这样更新它:

commitLocalUpdate(relay.environment,store => {
    const me = store.getRoot().getLinkedRecord("me")
    const giftRecipientConnectionRecord = me.getLinkedRecord("giftRecipientsConnection") // returns undefined right now    
    ... rest of the code
})
   

现在如何在本地状态下使用连接?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...