簡體   English   中英

GraphQL 類型的突變變量不知何故永遠不會改變

[英]GraphQL type of mutation variable somehow never changes

這種行為對我來說不再有意義。

我的突變:

export const DEVICE_CREATE_INPUT = gql`
    mutation CreateDevice(
        $attributeList: String
      ) {
        createDevice(
          input: {
            attributeList: $attributeList
          }
        ) {
          device {
            id
            _id
          }
        }
      }
`;

我的 typescript 代碼:

private createDeviceRequest(
    attributeList: string,
  ) {
    return this.apollo.mutate({
      mutation: DEVICE_CREATE_INPUT,
      variables: {
        attributeList
      }
    });
  }

當我嘗試發送突變(attributeList =“”)時,它給了我以下錯誤消息:

zone-evergreen.js:659 Unhandled Promise rejection: Variable "$attributeList" of type "String" used in position expecting type "Iterable!". ; Zone: <root> ; Task: Promise.then ; Value: Error: Variable "$attributeList" of type "String" used in position expecting type "Iterable!".
    at new ApolloError (index.js:26)
    at Object.next (QueryManager.js:88)
    at notifySubscription (Observable.js:135)
    at onNotify (Observable.js:179)
    at SubscriptionObserver.next (Observable.js:235)
    at iteration.js:4
    at Array.forEach (<anonymous>)
    at iterateObserversSafely (iteration.js:4)
    at Object.next (Concast.js:25)
    at notifySubscription (Observable.js:135) Error: Variable "$attributeList" of type "String" used in position expecting type "Iterable!".
    at new ApolloError (http://localhost:8100/vendor.js:62615:28)
    at Object.next (http://localhost:8100/vendor.js:152614:53)
    at notifySubscription (http://localhost:8100/vendor.js:136374:18)
    at onNotify (http://localhost:8100/vendor.js:136418:3)
    at SubscriptionObserver.next (http://localhost:8100/vendor.js:136474:7)
    at http://localhost:8100/vendor.js:1059:68
    at Array.forEach (<anonymous>)
    at iterateObserversSafely (http://localhost:8100/vendor.js:1059:25)
    at Object.next (http://localhost:8100/vendor.js:70868:97)
    at notifySubscription (http://localhost:8100/vendor.js:136374:18)

在某些時候,我確實使用了“Iterable”類型。 但我想切換到字符串並在前端的任何地方都可以找到它。 如果我現在在我的前端代碼中對“Iterable”進行全面搜索,我什么也找不到了? 這是緩存問題嗎?

發生此錯誤是因為 createDevice 突變的預期輸入類型與提供的類型不匹配。 如果要使用 String 而不是 Iterable,則應將后端的 attributeList 的 typedef 從 Iterable 更改為 String。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM