简体   繁体   中英

GraphQL type of mutation variable somehow never changes

this behaviour does not make sense to me anymore.

My mutation:

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

My typescript code:

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

When I try to send the mutation (attributeList = "") it gives me following error message:

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)

I did use the type 'Iterable,' at some point. but I wanted to switch to string and changed it everywhere in the frontend where I could find it. If I do a full search now in my frontend code for 'Iterable' I find nothing anymore? Is this a cache problem?

This error occurred because expected input type for createDevice mutation doesn't match the provided type. If you want to use String instead of Iterable you should change typedef of attributeList at your backend from Iterable to String.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM