graphql-js

GraphQL: build query arguments from object

筅森魡賤 提交于 2020-12-13 03:27:35
问题 If I have an object: {"where":{"publishedAt_lt":"2018-01-01"}} How can I convert it to a string suitable for query arguments? articles(where: {publishedAt_lt: "2018-01-01"}) 回答1: This looks like an interesting library, I would suggest checking it out: https://www.npmjs.com/package/json-to-graphql-query But basically all we need to do is to convert the object to a string while ensuring the keys do not adopt double quotes and integers are not converted into strings, as that might not play well

Graphql-Access arguments in child resolvers

这一生的挚爱 提交于 2020-08-22 04:19:06
问题 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: RootQuery } and Resolver functions are like this { RootQuery: { getTotalVehicals: async (root, args, context) => { // args = {color: 'something'} return {}; }, TotalVehicleResponse: { totalCars: async (root, args, conext) => { // args is empty({}) here ......... .....

Can you make a graphql type both an input and output type?

心不动则不痛 提交于 2020-08-21 07:57:02
问题 I have some object types that I'd like to use as both input and output - for instance a currency type or a reservation type. How do I define my schema to have a type that supports both input and output - I don't want to duplicate code if I don't have to. I'd also prefer not to create duplicate input types of things like currency and status enums. export const ReservationInputType = new InputObjectType({ name: 'Reservation', fields: { hotelId: { type: IntType }, rooms: { type: new List

Can you make a graphql type both an input and output type?

霸气de小男生 提交于 2020-08-21 07:56:49
问题 I have some object types that I'd like to use as both input and output - for instance a currency type or a reservation type. How do I define my schema to have a type that supports both input and output - I don't want to duplicate code if I don't have to. I'd also prefer not to create duplicate input types of things like currency and status enums. export const ReservationInputType = new InputObjectType({ name: 'Reservation', fields: { hotelId: { type: IntType }, rooms: { type: new List

Can you make a graphql type both an input and output type?

半城伤御伤魂 提交于 2020-08-21 07:56:13
问题 I have some object types that I'd like to use as both input and output - for instance a currency type or a reservation type. How do I define my schema to have a type that supports both input and output - I don't want to duplicate code if I don't have to. I'd also prefer not to create duplicate input types of things like currency and status enums. export const ReservationInputType = new InputObjectType({ name: 'Reservation', fields: { hotelId: { type: IntType }, rooms: { type: new List

Unit Tests for GraphQL Node JS App

江枫思渺然 提交于 2020-07-22 02:51:08
问题 I developed a graphql node js app with custom resolvers. Can anyone point me to some documentation where it illustrates how to properly write unit tests for my service? Or if someone has done it before and can point me in the right direction that would be great! 回答1: In order to test each endpoint of your service, you need to perform a POST operation on specified URL with proper payload. The payload should be an object containing three attributes query - this is a GraphQL query that will be

Angular - Apollo: Client has not been defined yet

半世苍凉 提交于 2020-07-20 07:59:35
问题 I'm using apollo client for graphql. I set up the client in AppApolloModule that I'm importing in AppModule. I'm making a query in a service which is also imported right in the AppModule. Although the service runs before the AppApolloModule runs and hence apollo is not initialized when the query is made and I get this error Error: Client has not been defined yet AppApolloModule imports .... export class AppApolloModule { constructor( apollo: Apollo, httpLink: HttpLink, private userService:

How to throw multiple errors with express-graphql?

萝らか妹 提交于 2020-06-23 02:56:24
问题 In an express-graphql app, I have a userLogin resolver like so: const userLogin = async ({ id, password }), context, info) => { if (!id) { throw new Error('No id provided.') } if (!password) { throw new Error('No password provided.') } // actual resolver logic here // … } If the user doesn't provide an id AND a password , it will throw only one error. { "errors": [ { "message": "No id provided.", "locations": [ { "line": 2, "column": 3 } ], "path": [ "userLogin" ] } ], "data": { "userLogin":