graphql-js | https | GraphQL library
kandi X-RAY | graphql-js Summary
kandi X-RAY | graphql-js Summary
https://www.howtographql.com/graphql-js/1-getting-started/
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Publish a new vote .
- Perform a feed
- Login Token handler
- Gets the user id from a request
- Create a new link
- Signup to the user .
- Creates a new link by parent .
- Gets the votes for a person .
- Links a parent person to a parent .
- Retrieve a user .
graphql-js Key Features
graphql-js Examples and Code Snippets
Community Discussions
Trending Discussions on graphql-js
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 am receiving error, compiling graphql doesn't work because of the graphql-js dependency.
...ANSWER
Answered 2022-Jan-12 at 05:45Try to use require(“module”)
or if that's the way you doing it, you sould try import("module")
. Maybe this will help.
QUESTION
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 /graphql
endpoint.
React is running on http://localhost:4200/
.
Node.js is running on http://localhost:3333/
.
According to GraphQL instructions for Node.js I run Node.js server. I have created two endpoints /api
and /graphql
.
ANSWER
Answered 2021-Sep-30 at 11:38To fix issue there was 2 steps to do:
- In React I should fetch from endpoint with port
fetch('http://localhost:3333/graphql',(...))
- In Node.js there is need to use
cors
library
QUESTION
GraphQL allows you to specify whether a field is to be optional or not (add !
)
Using the Node API, I cannot find that option.
see https://graphql.org/graphql-js/constructing-types/
I also went through the types without luck
see https://github.com/graphql/graphql-js/blob/main/src/index.ts
What am I missing?
I basically want
...ANSWER
Answered 2021-Aug-08 at 09:39I found the answer
QUESTION
What is the difference between graphql-js buildSchema
and the apollo-server gql
? They appear to do a very similar job.
ANSWER
Answered 2021-May-08 at 08:36Firstly 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 gql
.
Quick bit of background: the graphql-js
package provides an official reference implementation of GraphQL in Javascript. It provides two important things basically:
- The
graphql
function, which will process any GraphQL query against aGraphQLSchema
object (the GraphQLSchema object is how graphql-js represents your parsed schema). - A bunch of utility functions and types for building and validating the
GraphQLSchema
objects used by thegraphql
function 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
parse
function). - Step 2: AST -> GraphQLSchema (done by the
buildASTSchema
function).
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:
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
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
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
...ANSWER
Answered 2021-Mar-06 at 07:59Since you have mentioned about using neo4j-graphql-js library. You can do something like this:
QUESTION
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
...ANSWER
Answered 2021-Feb-25 at 07:09I was accidentally running
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install graphql-js
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