apollo-server

Expose HTTP GET API in GraphQL Apollo Server v2.0

我们两清 提交于 2020-07-10 10:26:43
问题 I am using Apollo Server v2.0 (without middleware) as part of my project and I would like to add support for a HTTP GET endpoint to for file downloads. Is there a way to expose an API endpoint without using apollo-server-express? Thank you 回答1: No. While apollo-server currently uses express under the hood, the Express instance is not exposed as a property on the ApolloServer instance. In order to expose any additional endpoints, you'd need to migrate to apollo-server-express or any of the

Apollo Server: pass arguments to nested resolvers

扶醉桌前 提交于 2020-07-10 04:19:09
问题 My GraphQL query looks like this: { p1: property(someArgs: "some_value") { id nestedField { id moreNestedField { id } } } } On the server side, I'm using Apollo Server. I have a resolver for the property and other resolvers for nestedField and moreNestedField . I need to retrieve the value of someArgs on my nested resolvers. I tried to do this using the context available on the resolver: property: (_, {someArgs}, ctx) => { ctx.someArgs = someArgs; // Do something } But this won't work as the

Apollo Server: pass arguments to nested resolvers

元气小坏坏 提交于 2020-07-10 04:19:06
问题 My GraphQL query looks like this: { p1: property(someArgs: "some_value") { id nestedField { id moreNestedField { id } } } } On the server side, I'm using Apollo Server. I have a resolver for the property and other resolvers for nestedField and moreNestedField . I need to retrieve the value of someArgs on my nested resolvers. I tried to do this using the context available on the resolver: property: (_, {someArgs}, ctx) => { ctx.someArgs = someArgs; // Do something } But this won't work as the

MongoError: Topology is closed, please connect

∥☆過路亽.° 提交于 2020-07-03 06:45:35
问题 I'm a front-end dev trying to expand my horizons on a new Next project, learning Node, Mongo, and the server side of GraphQL for the first time. Apollo strikes me as the easiest way to jump in, as I've already used client-side Apollo on previous projects. I've been following the official docs, where I learned of apollo-datasource-mongodb (seemingly the best way to plug my Apollo Server straight into a local Mongo database. Unfortunately there don't seem to be any example repos of this package

Apollo GraphQL: Call a Mutation from the Server?

China☆狼群 提交于 2020-06-09 05:34:08
问题 I need to call a mutation from a cron job running on the server. I found this SO post, but the accepted answer said there was no way to do it. Then I found this on GitHub, from 2017: graphql-server is an network wrapper for graphql core function. if you don't want to use it over network, you can just run it standalone: import scheme from './scheme'; const query = `{ me { name } }`; const result = graphql(scheme, query); console.log(result); function documentation can be found here That looks

SyntaxError: Cannot use import statement outside a module

本小妞迷上赌 提交于 2020-06-07 08:05:47
问题 I've got an ApolloServer project that's giving me trouble, so I thought I might update it and ran into issues when using the latest Babel. My "index.js" is: require('dotenv').config() import {startServer} from './server' startServer() And when I run it I get the error "SyntaxError: Cannot use import statement outside a module". First I tried doing things to convince TPTB* that this was a module (with no success). So I changed the "import" to a "require" and this worked. But now I have about

Apollo 2.0.0 Graphql cookie session

冷暖自知 提交于 2020-05-25 06:30:06
问题 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 browser as http only. On subsequent request I validate the cookie that the browser passes back. It was all working fine and I could access the token from req.session.token in any other resolver and validate the jwt token saved in the cookie session.

useQuery returns undefined, But returns data on gql playground

馋奶兔 提交于 2020-05-24 05:58:06
问题 "@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 defined union for user query for error handling. type Query { user(id: ID!): UserReturn! } union UserReturn = User | Error type User { id: ID! username: String! email: String profileUrl: String createdAt: Date ads: [Doc!]! } type Error { message: String

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

女生的网名这么多〃 提交于 2020-05-24 05:14:27
问题 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 Mutation { addUser( name: String! email: String age: Int register_at: TimeStamp! ): Boolean! } type User { id: Int! name: String! email: String! age: Int! register_at: TimeStamp! } `; UserResolver.ts export const resolvers = { TimeStamp: timeStamp, Query: { getUser: async (_:

How can one upload an image to a KeystoneJS GraphQL endpoint?

末鹿安然 提交于 2020-05-17 07:01:34
问题 I'm using TinyMCE in a custom field for the KeystoneJS AdminUI, which is a React app. I'd like to upload images from the React front to the KeystoneJS GraphQL back. I can upload the images using a REST endpoint I added to the Keystone server -- passing TinyMCE an images_upload_handler callback -- but I'd like to take advantage of Keystone's already-built GraphQL endpoint for an Image list/type I've created. I first tried to use the approach detailed in this article, using axios to upload the