In this environment the sources for assign MUST be an object
See original GitHub issueHi,
Trying to use the GraphQL API with a non AppSync set up and using a server that’s been created using API Gateway and a Lambda.
I can call the API perfectly fine using an ID token I’ve either generated myself or from the Auth
library within AWS Amplify, but whenever trying to call the API using Amplify I get the following:
TypeError: In this environment the sources for assign MUST be an object. This error is a performance optimization and not spec compliant.
at Object.assign (blob:http://localhost:8081/7c7e07ee-d664-4756-b453-7471c07cb34d:324)
at APIClass.<anonymous> (blob:http://localhost:8081/7c7e07ee-d664-4756-b453-7471c07cb34d:133915)
at step (blob:http://localhost:8081/7c7e07ee-d664-4756-b453-7471c07cb34d:133372)
at Object.next (blob:http://localhost:8081/7c7e07ee-d664-4756-b453-7471c07cb34d:133302)
at fulfilled (blob:http://localhost:8081/7c7e07ee-d664-4756-b453-7471c07cb34d:133254)
at tryCallOne (blob:http://localhost:8081/7c7e07ee-d664-4756-b453-7471c07cb34d:3732)
at blob:http://localhost:8081/7c7e07ee-d664-4756-b453-7471c07cb34d:3833
at blob:http://localhost:8081/7c7e07ee-d664-4756-b453-7471c07cb34d:3113
at _callTimer (blob:http://localhost:8081/7c7e07ee-d664-4756-b453-7471c07cb34d:3002)
at _callImmediatesPass (blob:http://localhost:8081/7c7e07ee-d664-4756-b453-7471c07cb34d:3038)
I do have another issue open at the moment regarding HTTP method type, but for now I’ve updated the API to allow GET requests. The code in my React Native app looks like this:
import React, { Component } from 'react';
import Amplify, { API, Auth, graphqlOperation } from 'aws-amplify';
Amplify.Logger.LOG_LEVEL = 'DEBUG';
Amplify.configure({
API: {
graphql_endpoint: 'https://myurl.com/graphql',
graphql_headers: async () => {
const { idToken } = await Auth.currentSession();
const Authorization = idToken.getJwtToken();
console.log('ID token:', Authorization);
return { Authorization };
},
},
Auth: {
identityPoolId: '***,
region: '***',
userPoolId: '***',
userPoolWebClientId: '***',
}
});
export default class App extends Component {
async componentDidUpdate() {
if (this.props.authState !== 'signedIn') {
return null;
}
try {
const query = graphqlOperation('valid_query');
console.log(query);
await API.graphql(query);
} catch (error) {
console.log(error);
}
}
render() {
if (this.props.authState !== 'signedIn') {
return null;
}
// ...
}
}
The code has been simplified a bit, but the only thing missing is the authenticator which works perfectly fine.
My dependencies are:
"dependencies": {
"aws-amplify": "^1.0.8",
"aws-amplify-react-native": "^1.0.8",
"native-base": "^2.8.0",
"react": "16.4.1",
"react-native": "0.56.0"
},
Any idea why this might be happening?
Thanks, Gary
Issue Analytics
- State:
- Created 5 years ago
- Comments:14
Top Results From Across the Web
In this environment the sources for assign MUST be an ...
TypeError: In this environment the sources for assign MUST be an object. This error is a performance optimization and not spec compliant.
Read more >TypeError: In this environment the sources for assign ...
This error happens because in that RNE version the iconRight prop should be an object instead of boolean. This was changed in the...
Read more >Javascript – Error when creating new object from existing one ...
Javascript – Error when creating new object from existing one using `…`: In this environment the sources for assign MUST be an object....
Read more >Overview of Azure Policy
Azure Policy is a service in Azure, that you use to create, assign and, manage policy definitions in your Azure environment.
Read more >TypeError: 'x' is not iterable - JavaScript - MDN Web Docs
The non-iterable might turn to be undefined in some runtime environments. ... Instead you have to use Object.keys or Object.entries , to iterate...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I have the same issue, did you find a solution?
I also looked at the source of that error “In this environment the target of assign MUST be an object. This error is a performance optimization and not spec compliant.”. It comes from node_modules/react-native/Libraries/polyfills/Object.es6.js
and this is a comment for that polyfill
so it looks like aws-amplify uses Object.assign properly but for some reasons that polyfill is used. I am not sure how to skip that polyfill, I don’t need to support IOS8 and Android JSC.
I checked that polyfill and it looks like it has been fixed and now is spec-compliant https://github.com/facebook/react-native/commit/966bb63a80750757dc7a78d7d1f8960a2d8e25e0#diff-cb5173a6f8d88f7801f5127b94bfc330
so anyone with the problem should upgrade to react-native 0.57 and confirm if that helps to solve the issue, in my case I use Expo and the latest supported RN is 0.55.4 so I need to wait for the next Expo release
Great. Thank you for the feedback.