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:

2126 questions
19
votes
4 answers

Graphql-Access arguments in child resolvers

I am using apollo-server and apollo-graphql-tools and I have following schema type TotalVehicleResponse { totalCars: Int totalTrucks: Int } type RootQuery { getTotalVehicals(color: String): TotalVehicleResponse } schema { query:…
Manan Vaghasiya
  • 881
  • 1
  • 10
  • 25
18
votes
7 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
  • 143,271
  • 52
  • 317
  • 404
17
votes
6 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…
U.A
  • 2,991
  • 3
  • 24
  • 36
17
votes
7 answers

Apollo GraphQL Server + TypeScript

I've been working on a project lately, which has node.js + express + typescript + Apollo server stack. And while researching on Apollo client, I've stumbled upon TypeScript section. But nothing like that was for server, which leaves me to freedom of…
naffiq
  • 1,030
  • 1
  • 9
  • 19
17
votes
2 answers

How to combine a mutation and a query in a single query?

I have an operation getFoo that requires that the user is authenticated in order to access the resource. User authenticates using a mutation authenticate, e.g. mutation { authenticate (email: "foo", password: "bar") { id } } When user is…
Gajus
  • 69,002
  • 70
  • 275
  • 438
15
votes
2 answers

How to split type definitions and resolvers into separate files in Apollo Server

index.ts: const server = new ApolloServer({ typeDefs, resolvers, context: ({ req, res }: any) => ({ req, res }) }); UserSchema.ts export const typeDefs = gql` scalar TimeStamp type Query { getUser(id: Int!): User } type…
user13084267
14
votes
1 answer

File uploads with graphql-upload, apollo-server-fastify, and the NestJS code first approach

What is the correct implementation for receiving file uploads from a client on a server utilizing the following combination of packages/techniques (and their corresponding dependencies not listed):…
jengel
  • 323
  • 4
  • 10
14
votes
2 answers

How to know which fields were requested in a GraphQL query?

I have written a GraphQL query which like the one below: { posts { author { comments } comments } } I want to know how can I get the details about the requested child fields inside the posts resolver. I want to do it to avoid…
WitVault
  • 23,445
  • 19
  • 103
  • 133
14
votes
1 answer

How to create generics with the schema language?

Using facebook's reference library, I found a way to hack generic types like this: type PagedResource = (pagedQuery: PagedQuery) => PagedResponse ​ interface PagedQuery { query: Query; take: number; skip:…
Daniel Birowsky Popeski
  • 8,752
  • 12
  • 60
  • 125
13
votes
1 answer

Optional but non-nullable fields in GraphQL

In an update to our GraphQL API only the models _id field is required hence the ! in the below SDL language code. Other fields such as name don't have to be included on an update but also cannot have null value. Currently, excluding the ! from the…
Matthew P
  • 717
  • 1
  • 7
  • 22
13
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
  • 383
  • 1
  • 6
  • 17
13
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,…
Lin Du
  • 88,126
  • 95
  • 281
  • 483
13
votes
1 answer

Apollo Server timeout while waiting for stream data

I'm attempting to wait for the result of a stream with my Apollo Server. My resolver looks like this. async currentSubs() { try { const stream = gateway.subscription.search(search => { …
ToraRTC
  • 440
  • 2
  • 4
  • 15
13
votes
5 answers

apollostack/graphql-server - how to get the fields requested in a query from resolver

I am trying to figure out a clean way to work with queries and mongdb projections so I don't have to retrieve excessive information from the database. So assuming I have: // the query type Query { getUserByEmail(email: String!): User } And I…
Vikk
  • 617
  • 7
  • 17
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…