Apollo-link-rest: 突然変異の原因:ERRORエラー:ネットワークエラー:グローバルが定義されていません

作成日 2019年07月12日  ·  5コメント  ·  ソース: apollographql/apollo-link-rest


現在Angular7を使用しており、apollo-rest link 0.7.3

最終的にミューテーションが部分的に機能するようになり、 globalが初期化されず、このエラーが発生するという1つの問題があります。

core.js:15724 ERROR Error: Network error: global is not defined
    at new ApolloError (bundle.esm.js:60)
    at Object.error (bundle.esm.js:1032)
    at notifySubscription (Observable.js:134)
    at onNotify (Observable.js:165)
    at SubscriptionObserver.error (Observable.js:224)
    at Object.error (Observable.js:463)
    at notifySubscription (Observable.js:134)
    at onNotify (Observable.js:165)
    at SubscriptionObserver.error (Observable.js:224)
    at bundle.umd.js:807

クライアントを初期化します

const restLink = new RestLink({
    uri: 'http://localhost:5000/api',
    credentials: 'same-origin',
    headers: {
      Accept: 'application/json',
      'Content-Type': 'application/json'
    }
  });
  return {
    link: restLink,
    cache
  };

私はこの突然変異を持っています:

export const addTodo = gql`
    mutation addTodo($input: Todo!){
      addTodo(input: $input) @rest( type: "Todo", method: "POST", path: "/todos" ) {
       ...todoFragment
      }
  }
  ${todoFragment}
`;

私はそれを次のように実行します:

 add(text: string): void {

    this.apollo.mutate({
      mutation: addTodo,
      variables: {
        input: {
          description: text,
          completed: false
        }
      }
    }).subscribe(({data}) => {
      console.log('got data', data);
    }, (error) => {
      console.log('there was an error sending the query', error);
    });

エラーの原因となる線は下の写真です

Screen Shot 2019-07-12 at 12 17 35 PM

このglobal.FileListグローバルオブジェクトが未定義である理由はありますか?

// FileList/File are only available in some browser contexts
        // Notably: *not available* in react-native.
        if ((global.FileList && object instanceof FileList) ||
            (global.File && object instanceof File)) {
            // Object is a FileList or File object => no keys to convert!
            return object;
        }
help wanted 🛠 question❔

全てのコメント5件

polyfills.tsに行を追加する必要があったため、これは最初はangular-cliの問題のようです。

https://github.com/angular/angular-cli/issues/8160
しかし、これに対する応答は次のようになります: globals does not exists in browser and should not be in the client-side code

それはRESTLINKにあるべきですか?

それは私にとってのニュースです。React-Nativeやその他の環境では、 globalは存在しますか? ブラウザでは、 globalオブジェクトがウィンドウであるため、次のように実行できます。 window.global = windowは、存在することを保証しますか?

私がしたことはAngularで提案されたとおりでしたが、彼らはこれを一体と見なしています。 これは私が一番下でしたことです:

https://github.com/fkolar/todo-rest/blob/master/src/polyfills.ts

https://github.com/fkolar/todo-rest

私はこれがハックであることに同意しますが、コードがブラウザーで実行されるのか、react-nativeで実行されるのかを知っているのはあなただけです。 Apollo-link-restを書くためのより良い方法を知っている/リンクできる場合は、変更をサポートします! 残念ながら、 windowはモバイルには存在しないため、ここで少し立ち往生しています。

私はちょうどこの問題にぶつかりました..すでに解決策はありますか?

このページは役に立ちましたか?
0 / 5 - 0 評価