kandi X-RAY | graphql-js Summary
kandi X-RAY | graphql-js Summary
Top functions reviewed by kandi - BETA
graphql-js Key Features
graphql-js Examples and Code Snippets
Trending Discussions on graphql-js
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
I'm sure that there are many items for deleting also with current id which I used for delete this is my code
ANSWERAnswered 2022-Mar-27 at 23:21
I gat it. Instead
where. Prisma supports filtering with where query option.
I am receiving error, compiling graphql doesn't work because of the graphql-js dependency....
ANSWERAnswered 2022-Jan-12 at 05:45
Try to use
require(“module”) or if that's the way you doing it, you sould try
import("module"). Maybe this will help.
I setup two projects, Node.js and React in Nx monorepo. I would like to use GraphQL for communication. Projects I'm running with command
nx serve api(Node.js) and
nx serve totodile (React). Problem is that React cannot access data from
React is running on
Node.js is running on
According to GraphQL instructions for Node.js I run Node.js server. I have created two endpoints
ANSWERAnswered 2021-Sep-30 at 11:38
To fix issue there was 2 steps to do:
- In React I should fetch from endpoint with port
- In Node.js there is need to use
GraphQL allows you to specify whether a field is to be optional or not (add
Using the Node API, I cannot find that option.
I also went through the types without luck
What am I missing?
I basically want...
ANSWERAnswered 2021-Aug-08 at 09:39
I found the answer
ANSWERAnswered 2021-May-08 at 08:36
Firstly note, apollo-server's
gql is actually a re-export from graphql-tag.
graphql-tag is a ~150 line package who's default and pretty much only useful export is
Quick bit of background: the
graphqlfunction, which will process any GraphQL query against a
GraphQLSchemaobject (the GraphQLSchema object is how graphql-js represents your parsed schema).
- A bunch of utility functions and types for building and validating the
GraphQLSchemaobjects used by the
graphqlfunction from strings.
Now, this is the part that ultimately confused me: in
graphql-js, taking a string and turning it into a
GraphQLSchema object is a two step process:
- Step 1: String -> AST (done by the
- Step 2: AST -> GraphQLSchema (done by the
It is like this is because the AST (Abstract Syntax Tree) is useful to a bunch of other tools which aren't even necessarily aware of GraphQL (for example see https://astexplorer.net/), where as the GraphQLSchema is only meaningful to graphql-js and related softwares.
graphql-js exposes the functions for doing both steps and these are reused by downstream implementors (like Apollo).
buildSchema is just a convenience wrapper to combine these two steps. It's literally this:
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
Can somebody please explain why there is this seemingly arbitrary usage of
async? When and why I should use it? Thanks in advance.
ANSWERAnswered 2021-Apr-30 at 09:51
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
The last concept to understand is
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.
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:...
ANSWERAnswered 2021-Apr-03 at 11:14
This part is not strictly related to auth [reasons] ... creating
post mutation will work without that. But:
postmutation creates an [
Link] entry with a relation (to
Userin prisma schema meaning docs );
postedByis a virtual field - 'Relation fields define connections between models at the Prisma level and do not exist in the database. ';
postmutation returns a
Posttype - then 'asked' return object can contain
postedByfield (and its
postedByfield is queried (as part of mutation result tree), it (related
Userobject/type - graphql context) must be resolved using
function postedBy(parent, args, context);
In resolver body we're using/working with "Prisma client" - ORM lib, then:
Assume I have the following schema:
ANSWERAnswered 2021-Mar-19 at 06:58
I 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.
I am trying to write a query with AND operator to extract data from neo4j in GraphQL but it doesn't return any result. I am using neo4j-graphql-js library. I have the following schema...
ANSWERAnswered 2021-Mar-06 at 07:59
Since you have mentioned about using neo4j-graphql-js library. You can do something like this:
I am trying to setup a relationship type in Grandstack. I am having issues getting things to run correctly. Even when I copy the guide into my project and try to run it ... things do not work. Here is what they have at https://grandstack.io/docs/guide-graphql-schema-design...
ANSWERAnswered 2021-Feb-25 at 07:09
I was accidentally running
No vulnerabilities reported
Reuse Trending Solutions
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page