如何将对象传递到Apollo Link状态?

时间:2018-10-30 01:11:48

标签: graphql apollo

我的默认状态定义如下:

const defaults = {
    activeModal: {
        __typename: 'ActiveModal',
        currentModal: null,
        orderItem: null
    }
}

然后我有突变解析器:

openModal: (_, { currentModal, orderItem }, { cache }) => {
    const data = {
        activeModal: {
            __typename: 'ActiveModal',
            currentModal,
            orderItem
        }
    }
    cache.writeData({ data })

然后我有突变:

export const OPEN_MODAL_MUTATION = gql`
  mutation OPEN_MODAL_MUTATION($currentModal: String!, $orderItem: Json) {
    openModal(currentModal: $currentModal,orderItem: $orderItem) @client 
  }
`

尽管我不确定$orderItem: Json,因为orderItem是我要传递的对象。这是正确的吗?

然后我有我的突变渲染道具:

<Mutation
    mutation={OPEN_MODAL_MUTATION}
    variables={{ currentModal: 'OrderDetailsModal', orderItem: { ...orderItem } }}
>
... onClick mutation...
</Mutation>

currentModal在全局状态下更新良好,但我无法传递该orderItem对象。如果我这样做,例如orderItem: orderItem.id,我会得到id,但是当我传递整个orderItem对象时,我什么也不会得到。

0 个答案:

没有答案