Prisma added new column but I'm unable to query it, recieve error 400 - database

I recently added a new boolean attribute to my org table. I checked with prisma studio to verify that I added the column correctly and tried to mutate it, which worked perfectly. I am now trying to query that value to use it in my code, but I keep receiving "Network error: Response not successful: Received status code 400". I also received this message in the response: "Cannot query field "inboxEnabled" on type "Organization"."
My query is:
import gql from 'graphql-tag'
export default gql`
query Organization ($id: ID!) {
organization (id: $id) {
id
inboxEnabled
}
}
`
Out of ideas, I tried to query a different boolean attribute to see if I obtained the same error but it worked just fine. I've done prisma db push and prisma generate multiple times and re-started the back-end to no avail.

Related

Merge query results of queryOneEntityById and queryAllEntitiesByIds in Apollo by __typename

There are two queries to get Posts. One is to get specific post by id (returns object)
query PostById ($id : ID!) {
post (id: $id) {
title
description
}
}
another one is to get all posts by ids (returns array of objects)
query PostsByIds ($ids : ID!) {
posts (ids: $ids) {
title
description
}
}
Entities in both of them have same __typename though from what I see Apollo caches them separately.
Is there a way to tell Apollo to treat everything with same __typename as a part of one data pool? So for example if we already have Post with id===1 received with PostsByIds([1]) on the call to PostById(1) apollo leverage cached data and not making API call?

Randomly graphql error "field 'apellido' not found in type: 'profesores'"

I'm working with a React App, using Heroku and Hasura.
After creating the column "apellido" in my table "profesor" in Hasura, i have been getting randomly this error whenever i'm trying to retrieve the "apellido" data from "profesor"
field 'apellido' not found in type: 'profesores'"
in, for example, this subscription.
subscription GetProfesor2($profesorKey: uuid!) {
profesores(where: { key: { _eq: $profesorKey } }) {
key
nombre
apellido
editor
}
}
For some reason, my react SPA sometimes throws this error, getting stuck randomly because of it.
If i spam f5, sometimes it works and i'm able to navigate and do stuff, but if i reload again or change users, there's a chance for the error to appear and i'm forced to just spam f5 until it dissapears.
I tried to run yarn-codegen after creating the column "apellido" in my table before uploading the code, "reload" the metadata in hasura and trying to find if there's a setup in hasura but was unable to find anything. []
Sorry about the info but i'm a novice at this so it's hard to know what or where i should look.

Firebase GET request orderby 400 bad request

For a get request, I am trying to user order by like below but always get a 400 bad request. Here, multiple users can have multiple blog posts each with a unique id like b1 in screenshot below. The long sequence of characters is the uid of a user under blogs. Each user has their own uid.
https://assignment-c3557-default-rtdb.asia-southeast1.firebasedatabase.app/blogs.json?orderBy="createdAt"
I followed the documentation here
https://firebase.google.com/docs/database/rest/retrieve-data
All I am doing is issuing a simple GET request in react js as follows:
const resp = await fetch(`https://assignment-c3557-default-rtdb.asia-southeast1.firebasedatabase.app/blogs.json?orderBy="createdAt"``)
const data = await resp.json()
if(!resp.ok) { ... }
Below is the database single entry for schema reference
As I said in my previous comment, this URL is invalid:
https://assignment-c3557-default-rtdb.asia-southeast1.firebasedatabase.app/blogs.json/orderBy="createdAt"
                                                                                     ^
The query portion of a URL starts with a ? character.
https://assignment-c3557-default-rtdb.asia-southeast1.firebasedatabase.app/blogs.json?orderBy="createdAt"
                                                                                     ^
Firebase Realtime Database - Adding query to Axios GET request?
I followed the above similar issue resolution to solve my problem

Good way to query server object being in local cache

So I have a database that store users. When someone log on my website, it stores in apollo cache a user as currentUser. And I only store his id.
So I made a query to get a user by passing his id :
query {
user(id: "id") {
id
username
avatar
}
}
But everytime I wanna get data for that user I need to make two query (the first one locally to get back his id from the cache and a second one to the server).
const GET_CURRENT_USER = gql`
query getCurrentUser {
currentUser #client
}
`;
const GET_USER_DATA = gql`
query getUser($id: String!) {
user(id: $id) {
id
username
avatar
}
}
`;
const currentUserData = useQuery(GET_CURRENT_USER);
const { currentUser } = currentUserData.data;
const { data, loading } = useQuery(GET_USER_DATA, {
variables: { id: currentUser.id },
fetchPolicy: "cache-and-network"
});
Is here a way that I can reduce that to only one query (the one to the server) ?
id value stored in the cache can be read using readQuery, you can store it in other global store/state, f.e. redux.
If you're using apollo cache as global store then using queries is a natural part of this process.
Using readQuery you can read the value without querying (but doing the same). One query 'saved' ;)
Deeper integration (additional query, local resolver) is not a good thing - creating unnecessary dependencies.
If you want to reuse this "unneccessary query" extract it to some module or create a custom hook (id read/used/saved once during initialization) - probably the best solution for this scenario.
Another solutions:
make login process providing user data - for some inspiration take a look at apollo-universal-starter-kit - but this is for initial data only (login/avatar changing during session??) - further user querying still needs an id parameter - it must be stored and read somewhere in the app.
make id optional parameter (for getUser query - if you can change backend) - if not provided then return data for current user (id read from session/token)

Apollo is mixing results from a GraphQL Query in React

I am making a call that returns questions and their answers. When I make this directly to the server, the response is as expected. Additionally, when react makes the call and I check developer tools, the response is as expected.
Once I get a response from Apollo, the data is mixed and results are bleeding into one another.
You will notice in these two images, the results are the same after a few results are expanded. I am not sure what could be causing this.
Why would freeform be combining?
My setup is like this:
I import the query and then run this on the client which is Apollo:
this.props.client.query({ query: getCoreObjectsQuery, variables: { companyId: 1}})
.then((result) => {
console.log(result, 'getCoreObjectsQuery')
From there, when I go to look at getCoreObjectsQuery, it looks like the above images!
Wow! Turns out to be an Apollo Client caching error.
Kamranicus.com has a really helpful article on this, but to anybody looking for a quick fix:
__typename #skip(if: true)
questions{
id
__typename #skip(if: true)
coreId
question
isCore
type
answer:answerForCoreId{
id
__typename #skip(if: true)
freeform
url
choice {
id
__typename #skip(if: true)
}
}
}
id and _id cache!

Resources