ERROR [TypeError: undefined is not an object (evaluating 'globalThis.localStorage.getItem')] - expo

I am trying to just select everything from a table from supabase. When I perform my fetch function, this is thrown and I dont know why.I have my URL and Key set into my supbase.js file.
picture of fetch function

Weights seems to be your data type.
Try this instead:
const {data: Weights, error} = await supabase.from('Weights').select('*');
console.log(JSON.parse(data));
return data;

Supabase parses the response and returns an object, so you don't need to parse it by yourself. Trying to parse what is already an object throws an error, and that is what was happening in your case.
The following should work!
const {data, error} = await supabase.from('Weights').select('*');
console.log(data);
return data;

Related

Flutter/Dart - Suggestions for how to Troubleshoot a Future?

Though it was working previously, for some reason my code has now stopped working. Though it fetches the required json data, the build doesn't render. The error on my app page which is supposed to display a page view was;
type String is not a subtype of 'Map<String,dynamic>'
But after some tweaks, now the error is;
invalid arguments(s)
I think I may have narrowed it down to the Future;
FutureBuilder<List<SpeakContent>> futureStage() {
return new FutureBuilder<List<SpeakContent>>(
future: downloadJSON(),
builder: (context, snapshot) {
if (snapshot.hasData) {
print("Snapshot has data.");
List<SpeakContent> speakcrafts = snapshot.data;
return new CustomPageView(speakcrafts);
} else if (snapshot.hasError) {
return Text('${snapshot.error}');
}
return new CircularProgressIndicator();
},
);
}
Future<List<SpeakContent>> downloadJSON() async {
final jsonEndpoint =
"http://example.com/getContent.php?";
final response = await get(jsonEndpoint);
if (response.statusCode == 200) {
List speakcrafts = json.decode(response.body);
debugPrint(speakcrafts.toString());
return speakcrafts
.map((speakcraft) => new SpeakContent.fromJson(speakcraft))
.toList();
} else
throw Exception('We were not able to successfully download the json data.');
}
Although it doesn't throw an error, I've noticed that it doesn't print my test statement after the "if (snapshot.hasData)" line.
Shouldn't I see "Snapshot has data." appear in my Android Studio console?
Based on what you provided, this
type String is not a subtype of 'Map<String,dynamic>'
must be this:
return Text('${snapshot.error}');
which means that your downloadJSON() threw an exception. In that case, print('Snapshot has data.'); never executes and the next case that I quoted above is executed.
Please put a breakpoint in the body of downloadJSON(), run it line by line and see what's thrown where.
ALSO, you are making an irrelevant but big mistake here. Do not call downloadJSON() like this. This function is executed at every re-render, which can be many times. You are initiating a JSON download at every redraw of your widget. This may stack up your backend bills... I explain it in this talk in more detail: https://youtu.be/vPHxckiSmKY?t=4771
After performing the troubleshooting tips as suggested by Gazihan Alankus and scrimau, I've found the culprit which was a single null entry in the MYSQL Database. Scary... gotta find out how to prevent that problem in the future.

cache.readQuery using #client raises: Cannot read property 'kind' of undefined

I've created very simple "login" page that is supposed to store 'email' and 'password' in local cache and then, onSubmit, to display stored values on console (this is done with mutation in resolvers.js).
Saving email and password values to the cache seems to work correctly but every time I try to read values from the cache I get "Network error: Cannot read property 'kind' of undefined". Any clues what is wrong with that?
My minimal example:
https://codesandbox.io/s/jv6mx6yoo9
The problem was the lack of query parameter name in a call to readQuery (thanks to #hwillson on apollo-react #slack for pointing this out):
const LOGIN_DATA_QUERY = gql`
query GetLoginData {
email #client
password #client
}
`;
// (...)
const data = cache.readQuery({ LOGIN_DATA_QUERY });
should be:
const data = cache.readQuery({ query: LOGIN_DATA_QUERY });

DynamoDb delete non-existent item does not fail, why?

I am deleting a non-existing record from the dynamodb table using dynamoDbMapper.delete(object) which uses default DynamoDBDeleteExpression
I was expecting some sort of exception to arise since the record is absent from the DB but it does nothing. It does not even have a return type which could tell if the delete was successful or failure. Is there a way to add a delete expression or something which will make my delete throw an exception if the item is absent from the db?
It is by design:
Unless you specify conditions, the DeleteItem is an idempotent operation; running it multiple times on the same item or attribute does not result in an error response.
FROM: https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_DeleteItem.html
It's possible to utilize ReturnValues to determine if delete did anything or not. If ReturnValues.Attributes is empty, it means delete didn't find a record to delete, and you can throw an error in this case. Example in JavaScript:
async function deleteWithThrowIfNotExists() {
const dynamo = new AWS.DynamoDB.DocumentClient();
const parameters = {
Key: {
user: 'john'
},
ReturnValues: 'ALL_OLD',
TableName: 'users'
};
const response = await dynamo.delete(parameters).promise();
if (!response.Attributes) {
throw new Error('Cannot delete item that does not exist')
}
}
You can first load the item, and if item doesn't exists you can throw exception otherwise delete it.

how Apollo client optimisticResponse working

http://dev.apollodata.com/react/mutations.html
I am trying out with optimisticResponse, but i am confused... and couldn't get it working on my local.
My questions are:
will optimisticResponse update the props and hence the re-render? how important is __typename: 'Mutation' can you leave it?
updateQueries is for new record appear? is this function trigger automatically or you need to invoke it?
is there any full example of out there which include the apollo server side?
Solution found:
const networkInterface = createNetworkInterface('http://localhost:8080/graphql');
this.client = new ApolloClient({
networkInterface,
dataIdFromObject: r => r.id
}
);
dataIdFromObject is the one thing i am missing during the Apolloclient initiation
dataIdFromObject (Object) => string
A function that returns a object identifier given a particular result object.
it will give unique ID for all result object.

Deleting a record with ember-model

I try to delete a record, a DELETE request is sent to the server but the request seems not correct:
What is done:
DELETE
/books
+ body json format
What I expect:
DELETE
/books/123
+ no body
What is really expected in ember-model ?
How can I achieve my expectation (DELETE books/123)
Looking at the source code, it seams clear how ember-model does the DELETE operation:
deleteRecord: function(record) {
var primaryKey = get(record.constructor, 'primaryKey'),
url = this.buildURL(record.constructor, get(record, primaryKey)),
self = this;
return this.ajax(url, record.toJSON(), "DELETE").then(function(data) {
self.didDeleteRecord(record, data);
});
}
basically the resulting format is: DELETE /books/123 + JSON body.
If your backend expects something else then the only way to change it would be to rewrite the deleteRecord for your custom needs. But IMO the simplest thing you could do is to just ignore the JSON body.
Hope it helps.