howtographql | The Fullstack Tutorial for GraphQL | GraphQL library
kandi X-RAY | howtographql Summary
kandi X-RAY | howtographql Summary
The Fullstack Tutorial for GraphQL
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of howtographql
howtographql Key Features
howtographql Examples and Code Snippets
Community Discussions
Trending Discussions on howtographql
QUESTION
I'm learning to write apollo server by following a graphql tutorial https://www.howtographql.com/graphql-js/3-a-simple-mutation/ but when I try to write a delete mutation and use it in the GraphQL Playground, I get null after executing, and if I check data in the Prisma studio there is no change
mutation delete and server response
I'm sure that there are many items for deleting also with current id which I used for delete this is my code
...ANSWER
Answered 2022-Mar-27 at 23:21I gat it. Instead data
use where
. Prisma supports filtering with where query option.
QUESTION
I installed golang and started with this tutorial: https://www.howtographql.com/graphql-go/1-getting-started/
When I run:
...ANSWER
Answered 2022-Feb-20 at 21:12QUESTION
I am following this tutorial on GraphQL with Sangria. I am wondering about the following line
...ANSWER
Answered 2021-Jul-15 at 07:42It is the Extractor pattern, you can reach the same result implementing the unapply method on your arbitrary object (like shown in the example). When you create a case class
the compiler produces an unapply method for you, so you can do:
QUESTION
I am in the Getting Started React + Apollo chapter: https://www.howtographql.com/react-apollo/1-getting-started/
When I enter the following query in the Prisma Playground (as the tutorial tells me to do):
...ANSWER
Answered 2021-Mar-23 at 17:39That's because the server has been written with the business rule in mind that a Post will always belong to a User. The database has a NOT NULL postedById field on the Link table i.e. a post will always have a user id attached to it. You need to make postedById field nullable in the Link model in the Prisma ORM schema. To fix this, make the following changes on server side code and relaunch the server
In the server folder go to schema.prisma file, and make both fields postedBy and postedById optional/nullable by suffixing them with ?
QUESTION
I completed this tutorial on making a graphql-node backend server built on Prisma2 and GraphQL. The tutorial doesn't explain why it writes some Resolver functions async
and some not.
I thought that the async
was added to functions that interacted with the database, but you can see this resolver gets data from the database but doesn't use async
. But in this resolver it does use async
.
Can somebody please explain why there is this seemingly arbitrary usage of async
? When and why I should use it? Thanks in advance.
ANSWER
Answered 2021-Apr-30 at 09:51The first thing you should do is read up on Promises. Promises are a way in JavaScript to encapsulate computations that are still ongoing. This is usually the case when you talk to an external service like a database or the operating system. They have been replacing callback style APIs.
In GraphQL a resolver can either return a value or a Promise that resolves to a value. This means, you can freely choose returning a value or a Promise, but if you call a database function like Prisma, you will get a Promise back, so you are kind of forced to stay "in Promise land", as there is no way to turn a Promise into a value. You can only chain functions, that should be executed with the value "in the future" (with then
).
The last concept to understand is async
/await
. These async syntax is an addition to JavaScript syntax, that makes working with Promises easier. With await
, you can stop the execution of a function until a value in a Promise arrives. Now, this looks like you are turning a Promise back into a value, but in reality, you function implicitly returns a Promise. For the VM to know about this, you have to state, that a function might use async
by adding the keyword await
in front of the function.
So when do you use async
for a resolver? You could do it all the time, and the code would be correct. But doing it, even when you don't need to (e.g. you are not talking to a service) might have some performance implications. So it's better to only do it, if you really want to use the await
keyword somewhere. I hope this can get you started with the concepts above, there is really a lot to learn. Maybe just go with your intuition and TypeScript errors until you deeply understand what is going on.
QUESTION
I hope I can get clarity when asking this question since GraphQL is a fairly obscure concept and there aren't that many answers online.
In the tutorial (https://www.howtographql.com/graphql-js/6-authentication/) in the #Resolving relations section near the middle of the page there's this code:
...ANSWER
Answered 2021-Apr-03 at 11:14This part is not strictly related to auth [reasons] ... creating post
mutation will work without that. But:
post
mutation creates an [Link
] entry with a relation (toUser
in prisma schema meaning docs );postedBy
is a virtual field - 'Relation fields define connections between models at the Prisma level and do not exist in the database. ';post
mutation returns aPost
type - then 'asked' return object can containpostedBy
field (and itsUser
object/type subfield[-s]);- when
postedBy
field is queried (as part of mutation result tree), it (relatedUser
object/type - graphql context) must be resolved usingfunction postedBy(parent, args, context)
;
In resolver body we're using/working with "Prisma client" - ORM lib, then:
QUESTION
I am using the curl command to have a graphQL server, I am following docs from the website https://www.howtographql.com/react-apollo/1-getting-started/
when I am running the command:-
curl https://codeload.github.com/howtographql/react-apollo/tar.gz/starter | tar -xz --strip=1 react-apollo-starter/server
for downloading the server code as mentioned in the docs,The error of the above command was in the image
please help to rectify the problem
...ANSWER
Answered 2021-Mar-20 at 19:34got solved the issue,if you face similar kind of issue refer:https://github.com/howtographql/react-apollo/issues/85#issuecomment-671262863
QUESTION
Assume I have the following schema:
BOOKS COLLECTION:
...ANSWER
Answered 2021-Mar-19 at 06:58I think it depends on your use cases. Says you only maintain 1-way pointer that keeps books array in author document, if you have a use case that requires searching for author by a certain book, you will need to do a full collection scan of author collection to find all matches. So without much knowledge of your actual scenario, it could be hard for us to comment on the necessity of 2 way pointer in your database.
This document is a good piece for your reading.
QUESTION
- Version: v12.19.0
- Platform: Linux ayungavis 5.4.0-48-generic #52~18.04.1-Ubuntu SMP Thu Sep 10 12:50:22 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
- Subsystem:
I tried to follow the tutorial from Adding a Database to GraphQL, this is the code of my script.ts
:
ANSWER
Answered 2020-Oct-12 at 07:17It seems that your issue is related to this. Currently there's an issue with Node.js version 12.19.0 that Heroku uses and there's a dependency named undici
that's causing the issue. It should work if you try it with Node 14 in Heroku.
QUESTION
I use the react-apollo boilerplate in my expo
project.
So far the project runs fine. But when I have interactions with my database it fails with:
Unhandled Rejection (Error): Network error: Response not successful: Received status code 400
and
The development server has disconnected.
and
So what is the best way to continue? This is the ApolloClient
that needs to be running for the connection with my database:
ANSWER
Answered 2020-Jul-18 at 05:18Actually it helped to restart the GraphQL server once again via yarn start
.
It not, try to rebuild all modules after cleaning.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install howtographql
Make sure to install a Node version manager (either fnm or nvm)
Point your environment to the version specified in .nvmrc.
Make sure to load .env to your environment variables (some shell loads it automatically, but if not, you can do: source .env to load it)
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page