graphql-js

Mocking GraphQL, MockList genertes only two items in the array

感情迁移 提交于 2019-12-07 13:53:19
问题 I am trying to generate a list of 10 items in my GraphQL mock server like this: import { makeExecutableSchema, addMockFunctionsToSchema, MockList } from 'graphql-tools'; import casual from 'casual'; import typeDefs from './schema.graphql'; export const schema = makeExecutableSchema({ typeDefs }); const mocks = { File: () => ({ path: casual.random_element([ '/assets/images/cars/1.JPG', '/assets/images/cars/2.JPG', '/assets/images/cars/3.JPG', '/assets/images/cars/4.JPG', '/assets/images/cars/5

Schema is not configured for mutations

こ雲淡風輕ζ 提交于 2019-12-07 07:10:22
问题 I have the following schema : import { GraphQLSchema, GraphQLObjectType, GraphQLInt, GraphQLString } from 'graphql'; let counter = 100; const schema = new GraphQLSchema({ // Browse: http://localhost:3000/graphql?query={counter,message} query: new GraphQLObjectType({ name: 'Query', fields: () => ({ counter: { type: GraphQLInt, resolve: () => counter }, message: { type: GraphQLString, resolve: () => 'Salem' } }) }), mutiation: new GraphQLObjectType({ name: 'Mutation', fields: () => ({

Gatsby.js: Filter GraphQL query by nested object property

梦想的初衷 提交于 2019-12-07 05:35:51
问题 I'm working on a news site which will have articles, each with one or multiple respective authors. If you click on an author's name, it will take you to a page displaying their information and a list of articles they have contributed to. So each article has an authors property, which in turn is an array of author objects with properties: full name, slug ( lowercase version of full name with spaces replaced by dashes ), etc. Is it possible to filter the articles by a particular author's slug

How to pass total count to the client in pageInfo

无人久伴 提交于 2019-12-06 23:00:42
问题 I use first after and last before to do pagination. hasNextPage and hasPreviousPage are very useful. But what I need is also the total count so that I can calculate and show things like page 5 of 343 pages on the client. Unfortunately that is not part of pageInfo even though I have the information on the server site. Can you please include a total field in the pageInfo and extend connectionFromArray to take in the total arrayLength like connectionFromArraySlice already does? Thanks 回答1:

Data null after saving entity with Moongose and GraphQL

人盡茶涼 提交于 2019-12-06 15:37:17
When saving an entity with mongoose and graphql the following happens: First method to save: create(budgetProps){ const budget = new Budget(budgetProps); return budget.save(); } The result is as follows: { "data": { "addBudget": { "_id": "59fbdefaa7b0a81180dd2c9c", "tiempoAproximado": 2245.5, "User": { "name": null, "organization": null }, "Vehicle": { "name": null, "type": null } } } } Using this method: create(budgetProps){ const budget = new Budget(budgetProps); return budget.save().then((res)=>{ Budget.findById(res._id) .populate('User') .populate('Vehicle') .exec((err, newBudget)=> {

Apollo readQuery Fails Even Though Target Object is Present?

岁酱吖の 提交于 2019-12-06 07:04:38
I'm working on a call to readQuery. I'm getting an error message: modules.js?hash=2d0033b4773d9cb6f118946043f7a3d4385825fe:25847 Error: Can't find field resolutions({"id":"Resolution:DHSzPa8bvPCDjuAac"}) on object (ROOT_QUERY) { "resolutions": [ { "type": "id", "id": "Resolution:AepgCCio9KWGkwyMC", "generated": false }, { "type": "id", "id": "Resolution:DHSzPa8bvPCDjuAac", // <==ID I'M SEEKING "generated": false } ], "user": { "type": "id", "id": "User:WWv57KsvqWeAoBNHY", "generated": false } }. The object with that id appears to be plainly visible as the second entry in the list of

Fetch additional data for a single item in a list query

£可爱£侵袭症+ 提交于 2019-12-06 05:46:59
Im trying to do something like this with React and Relay - smooth animation from list to single item. I currently have list component (list query) and single item component (node query) but there's a problem: these are two different, isolated views and queries, I can't think of an easy way to smootly animate between these two views. Easiest way would probably be to transform / scale that same list item: React part is simple, I'll calculate screen size on click and transform the list item to full-screen size. How about data? Is something like this possible with Relay? Can I fetch more data for

Graphql with nested mutations?

最后都变了- 提交于 2019-12-06 04:08:08
I am trying to figure out how to mutate a nested object with graphql mutations, if possible. For instance I have the following schema: type Event { id: String name: String description: String place: Place } type Place { id: String name: String location: Location } type Location { city: String country: String zip: String } type Query { events: [Event] } type Mutation { updateEvent(id: String, name: String, description: String): Event } schema { query: Query mutation: Mutation } How can I add the place information inside my updateEvent mutation? If you want to add a whole object to the mutation

How do I call an asynchronous node.js function from within a GraphQL resolver requiring a return statement?

时光总嘲笑我的痴心妄想 提交于 2019-12-06 01:38:59
问题 The Hello World example provided on graphql.org/graphql-js for creating a simple GraphQL implementation is the following: var { graphql, buildSchema } = require('graphql'); // Construct a schema, using GraphQL schema language var schema = buildSchema(` type Query { hello: String } `); // The root provides a resolver function for each API endpoint var root = { hello: () => { return 'Hello World!'; } }; // Run the GraphQL query '{ hello }' and print out the response graphql(schema, '{ hello }',

GraphQL: Accessing another resolver/field output from a sibling resolver

微笑、不失礼 提交于 2019-12-05 21:36:44
问题 need some help. Let say Im requesting the following data: { parent { obj1 { value1 } obj2 { value2 } } } And I need the result of value2 in value1 resolver for calculation. Thought of returning a promise in in value2 and somehow take it in value1 resolver, but what if value2 resolver didn’t run yet? There`s any way it could be done? 回答1: My immediate thought is that you could use the context to achieve something like this. I'd imagine you could have a cache like object mixed with an event