現在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);
});
エラーの原因となる線は下の写真です
この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;
}
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
私はこれがハックであることに同意しますが、コードがブラウザーで実行されるのか、react-nativeで実行されるのかを知っているのはあなただけです。 Apollo-link-restを書くためのより良い方法を知っている/リンクできる場合は、変更をサポートします! 残念ながら、 window
はモバイルには存在しないため、ここで少し立ち往生しています。
私はちょうどこの問題にぶつかりました..すでに解決策はありますか?