Tag: javascript
-
Custom hook to log request and errors while using either useQuery or useMutation?
0 Requirement: Create a custom hook (useLoggedAPI) to call either useQuery or useMutation and add logs for request or errors. This utility function will be reused everywhere where there’s an GQL API call. What I have tried so far: /* eslint-disable @typescript-eslint/no-explicit-any */ import { useQuery, useMutation, AnyVariables, UseQueryArgs, DocumentInput, CombinedError, UseQueryResponse, UseMutationResponse, } from…
-
Resolve two GraphQL schema fields using one endpoint
2 There’s a situation where there are two possible types to fill data property. I have made a union type for that (ComponentItem) to determine which field needs to be returned. The first schema (ComponentItem1) should just be a hardcoded list but the second one (ComponentItem2) is more dynamic where it gets a searchTerm from…
-
I need to get context using websocket on appolo server
0 Before I could get the context using startStandaloneServer but now I have to use a websecket and I’m not getting the token how is the file server.Js import { ApolloServer } from ‘@apollo/server’; import { createServer } from ‘http’; import { expressMiddleware } from ‘@apollo/server/express4’; import express from ‘express’; import { ApolloServerPluginDrainHttpServer } from…
-
Do I need to close client stub after every request?
0 I am using dgraph-js and have an app.ts file which holds all the services variables such like the client stub export const dgraphStub = dgraph.clientStubFromCloudEndpoint( process.env.DGRAPH_URI!, process.env.DGRAPH_KEY! ); export const dgraphClient = new dgraph.DgraphClient(dgraphStub); dgraphClient.setDebugMode(true); Now when I do something in dgraph like below async function GetComment(commentId: string): Promise<IComment> { const txn = dgraphClient.newTxn({…
-
How to delete an object by pressing a button with onClick via mutation
0 There is code with GraphQL in bff and in the application part. This function is described as follows: shema.js: type Mutation { deleteCart(id: Int): [Cart] } index.js: deleteCart: (_, args) => { carts = carts.filter((c) => c.id !== args.id); return carts; } As declared in query: export const CART_ITEMS = gql` mutation DeleteCart ($id:…
-
Remove read-only fields before mutation in GraphQL
10 I’ve got a type called Article in my schema: type Article { id: ID! updated: DateTime headline: String subline: String } For updates to it, there’s a corresponding input type that is used by a updateArticle(id: ID!, article: ArticleInput!) mutation: input ArticleInput { headline: String subline: String } The mutation itself looks like this:…
-
Passing request parameter into middleware which uses ‘createHandler’ function of ‘graphql-http’
0 I have created an express server which uses GraphQL for handling requests over HTTP. Among others, the express server has the two middlewares below. app.use(authenticate); app.use(‘/graphql’, createHandler({ schema })); The authenticate middleware invokes a function which has req, res and next as parameters and in certain conditions assigns a value to req.user. How can…
-
Shopify app keeps reloading after implementing GraphQL API call?
0 I’m learning full stack dev by making a Shopify app, the stack is Javascript, React, Remix, and uses the GraphQL API. I’m consistently running into an issue with calling into the orders api call, the previously working web app will begin to repeatedly reload & then will fail with this error: This app can’t…
-
Passing request parameter into middleware using createHandler function of graphql-http
0 I have created an express server which uses GraphQL for handling requests over HTTP. Among others, the express server has the two middlewares below. app.use(authenticate); app.use(‘/graphql’, createHandler({ schema })); The authenticate middleware invokes a function which has req, res and next as parameters and in certain conditions assigns a value to req.user. How can…
-
Use custom decorator to add extra fields to TypeGraphQL @ObjectType class
0 Is there a way to create a custom class-level decorator that adds two parameters to a TypeGraphQL @ObjectType class? Example: @ObjectType() @Timestampable // custom decorator class User { @Field() email: string; } The @Timestampable decorator should add the createdAt and updatedAt props to the User class and the new props should show up in…