graphql-js

How to throw multiple errors with express-graphql?

孤街醉人 提交于 2020-06-23 02:56:01
问题 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":

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 do I set up GraphQL query so one or another argument is required, but not both

心已入冬 提交于 2020-05-23 09:51:05
问题 I'm just getting to grips with GraphQL, I have set up the following query: ​ type: UserType, args: { id: { name: 'id', type: new GraphQLNonNull(GraphQLID) }, email: { name: 'email', type: new GraphQLNonNull(GraphQLString) } }, resolve: (root, { id, email }, { db: { User } }, fieldASTs) => { ... } I would like to be able to pass either an 'id' or 'email' to the query, however, with this setup it requires both an id and email to be passed. Is there a way to set up the query so only one argument

How to Filter List/Queries With AND/OR operators AWS Amplify JavaScript GraphQL

两盒软妹~` 提交于 2020-04-16 02:33:14
问题 I am new to using AWS Amplify and GraphQL. Also just started building out React Native App - which is a lot of fun! I have a table called TimePeriods schema for it looks like this type TimePeriod @model { id: ID! name: String! startYear: String! endYear: String!, artworks: [ArtWorkTimePeriod] @connection (name: "TimePeriodArtWorks") #Many to Many Relationship artists: [ArtistTimePeriod] @connection (name: "TimePeriodArtists") #Many to Many Relationship } In the queries file generated by

How to Filter List/Queries With AND/OR operators AWS Amplify JavaScript GraphQL

旧巷老猫 提交于 2020-04-16 02:33:09
问题 I am new to using AWS Amplify and GraphQL. Also just started building out React Native App - which is a lot of fun! I have a table called TimePeriods schema for it looks like this type TimePeriod @model { id: ID! name: String! startYear: String! endYear: String!, artworks: [ArtWorkTimePeriod] @connection (name: "TimePeriodArtWorks") #Many to Many Relationship artists: [ArtistTimePeriod] @connection (name: "TimePeriodArtists") #Many to Many Relationship } In the queries file generated by

How can i run one mutation multiple times with different arguments in one request?

人盡茶涼 提交于 2020-03-16 09:00:23
问题 I have a mutation: const createSomethingMutation = gql` mutation($data: SomethingCreateInput!) { createSomething(data: $data) { something { id name } } } `; How do I create many Something s in one request? Do I need to create a new Mutation on my GraphQL server like this: mutation { addManySomethings(data: [SomethingCreateInput]): [Something] } Or is there a way to use the one existing createSomethingMutation from Apollo Client multiple times with different arguments in one request? 回答1: You

How can i run one mutation multiple times with different arguments in one request?

百般思念 提交于 2020-03-16 09:00:14
问题 I have a mutation: const createSomethingMutation = gql` mutation($data: SomethingCreateInput!) { createSomething(data: $data) { something { id name } } } `; How do I create many Something s in one request? Do I need to create a new Mutation on my GraphQL server like this: mutation { addManySomethings(data: [SomethingCreateInput]): [Something] } Or is there a way to use the one existing createSomethingMutation from Apollo Client multiple times with different arguments in one request? 回答1: You

graphql errors and status messages in graphql-js

南楼画角 提交于 2020-01-25 22:09:08
问题 I'm conceptually stuck with graphsql (using graphql-js). Lets's say the API user sends a query and the database-server is down and I'd like to return this information as an error in the in the data { errors } list. How can i access the errors object in data and push my own error messages (e.g. about the database-server outage) there? Next thing I am wondering about is how to add an addition messages object to the data object. Let's say The user has requested a database item by id (e.g. a

graphql errors and status messages in graphql-js

旧城冷巷雨未停 提交于 2020-01-25 22:09:05
问题 I'm conceptually stuck with graphsql (using graphql-js). Lets's say the API user sends a query and the database-server is down and I'd like to return this information as an error in the in the data { errors } list. How can i access the errors object in data and push my own error messages (e.g. about the database-server outage) there? Next thing I am wondering about is how to add an addition messages object to the data object. Let's say The user has requested a database item by id (e.g. a

querying graphql with node

浪子不回头ぞ 提交于 2020-01-14 13:49:07
问题 I am trying to query a graphQL endpoint but I can't figure out what I am doing wrong. How am I supposed to set up the graphQL object to pass over. If I am trying to pass { name { age } } How should I be wrapping this to get the correct response from the server? The full code I am currently working with is below var http = require('http') var qs = require('querystring') var options = { hostname: 'url', method: 'POST', path: '/query' } var req = http.request(options, function(res){ console.log(