Questions tagged [apollo-server]

Apollo Server is a GraphQL server for Express, Connect, Hapi and Koa, written in TypeScript

Apollo Server is a community-maintained open-source server.

It works with all Node.js HTTP server frameworks: Express, Connect, Hapi and Koa.

Useful links:

1540 questions
12
votes
1 answer

Testing useSubscription apollo hooks with react

Testing the useSubscription hook I'm finding a bit difficult, since the method is omitted/not documented on the Apollo docs (at time of writing). Presumably, it should be mocked using the from @apollo/react-testing, much like the…
12
votes
2 answers

What should be the GraphQL mutation return type when there is no data to return?

I have an Apollo GraphQL server and I have a mutation that deletes a record. This mutation receives the UUID of the resource, calls a REST (Ruby on Rails) API and that API just returns an HTTP code of success and an empty body (204 No Content) when…
Mario
  • 1,083
  • 1
  • 10
  • 35
12
votes
2 answers

What is the difference between apollo server and express-graphql

I would like to build an application and its recommended to use GraphQl for API, I am not sure which platform to select and what are the differences. apollo server vs express-graphql I need to use TypeScript for the project too. Any good Idea…
MJ X
  • 6,186
  • 8
  • 45
  • 77
12
votes
2 answers

GraphQL endpoint for file download

Is it possible to trigger a file download in a browser from the GraphQL endpoint on an apollo-server-express application? I have the endpoint written in a standard express app.get function (see below) but I would like to make use of the GraphQL…
jasonmerino
  • 3,090
  • 1
  • 17
  • 36
12
votes
2 answers

graphql, how to design input type when there are "add" and "update" mutation?

Here are my requirements: "add" mutation, every field(or called scalar) of BookInput input type should have additional type modifiers "!" to validate the non-null value. Which means when I add a book, the argument must have title and author field,…
slideshowp2
  • 38,463
  • 29
  • 127
  • 255
11
votes
4 answers

Log apollo-server GraphQL query and variables per request

When using apollo-server 2.2.1 or later, how can one log, for each request, the query and the variables? This seems like a simple requirement and common use case, but the documentation is very vague, and the query object passed to formatResponse no…
Dan Dascalescu
  • 110,650
  • 40
  • 276
  • 363
11
votes
1 answer

Apollo 2.0.0 Graphql cookie session

Can someone help me on this, My setup was as follows prior to Apollo 2.0, I had a server.js in which i used express and graphql-server-express I had a http only cookie session, when a user logs in I set the jwt token as a cookie and it is set in…
NUS
  • 323
  • 1
  • 6
  • 15
11
votes
1 answer

How to implement auto refresh token in graphql for jwt based authentication?

I am trying to figure out this scenario for my JWT based authentication in Apollo based graphql server (2.0) . Basically after login a user gets accessToken and refreshToken from server. AccessToken gets expired after certain period of time and…
WitVault
  • 19,604
  • 18
  • 88
  • 116
10
votes
1 answer

Apollo Server - GraphQL Error: There can be only one type named "Query"

I am new to GraphQL. I am following several guides on Internet in order to "create" a small app that uses Apollo Server + Express + GraphQL + MongoDB. I have tried to replicate this YT guide (he creates root.js file on typeDefs folder). This one…
Maramal
  • 1,913
  • 2
  • 24
  • 58
10
votes
1 answer

How to handle Errors with the Apollo stack

I'm using the Apollo Stack with graphql-server-express and apollo-client. Because my backend is not perfect errors can appear and therefore I have to respond to a request with an error for that path. Till now my main problem was authentication and…
Kordon
  • 254
  • 2
  • 12
10
votes
3 answers

Custom Error Object with Apollo Server

I'm trying to use a custom error with apollo-server and it seems that my custom error has a property (code) that isn't available from within formatError. import ExtendableError from 'es6-error' export default class MyError extends ExtendableError…
ThomasReggi
  • 42,912
  • 63
  • 199
  • 343
9
votes
0 answers

How can I correctly type the context object in Apollo Server?

I'm using apollo server with typescript and I'm having trouble getting the context parameter inside of my resolver to pick up that the name property on context is a string. Right now it's typed as any and I'd like it to be typed as string. I also…
Dennis Martinez
  • 5,406
  • 9
  • 43
  • 59
9
votes
5 answers

How to load a .graphql file using `apollo-server`?

I am currently loading the GraphQL schema using a separate .graphql file, but it is encapsulated within strings: schema.graphql const schema = ` type CourseType { _id: String! name: String! } type Query { courseType(_id: String):…
Sam Sverko
  • 911
  • 11
  • 21
9
votes
2 answers

I don't understand the GraphQL N+1 problem

So just yesterday i started learning graphql its really interesting, and quite easy to learn and understand actually. i started reading some articles and i found the N+1 problem. i found this example here Query # getting the top 100 reviews { …
wassimbj
  • 101
  • 1
  • 10
9
votes
3 answers

useQuery returns undefined, But returns data on gql playground

"@apollo/react-hooks": "^3.1.3", "apollo-client": "^2.6.8", Apollo client return undefined on react app but return the data on gql playground, I don't understand why don't it works on client-side but works on graphql playground. Schema I have…
C.K
  • 1,742
  • 1
  • 13
  • 29