risingstack / graffiti-mongoose Goto Github PK
View Code? Open in Web Editor NEW⚠️ DEVELOPMENT DISCONTINUED - Mongoose (MongoDB) adapter for graffiti (Node.js GraphQL ORM)
Home Page: https://risingstack-graffiti.signup.team/
License: MIT License
⚠️ DEVELOPMENT DISCONTINUED - Mongoose (MongoDB) adapter for graffiti (Node.js GraphQL ORM)
Home Page: https://risingstack-graffiti.signup.team/
License: MIT License
Hi, I've cloned the project and all the e2e singular query tests are failing. It's just happening to me or there's something wrong?
Is there any estimate time for mutation implementation?
Is there a way to wire up the existing model methods and statics with resolve functions?
i.e. if my model User
has a method User.statics.findSimilar()
is there a way for me to expose this as a GraphQL type?
If this was a new application I would use pre and post hooks but theres TONNES of existing business logic within the mongoose statics that I would rather not replicate by hand!
Any thoughts?
Hi,
I have a mongoose Schema, and I'd like to have a look at the original Graphql that is generated by graffiti-mongoose. Is there some way to let graffiti-mongoose export a Schema.js file?
btw, thank you for the great work 👍
I get an error if I use after
to fetch new items. Example query (below). Query is produced by Relay, but should be self explanatory.
query Product {
node(id:"UHJvZHVjdDo1MGEwNDU1ZDBkNmNhYjA1MmFlN2VmZTk=") {
...F1
}
}
fragment F0 on Attribute {
id,
name
}
fragment F1 on Product {
_attributeslhN3L:attributes(after:"Y29ubmVjdGlvbi41NDVhYzUzY2JlYjcwODYzMWJjODczYTA=",first:2) {
edges {
cursor,
node {
...F0,
id
}
},
pageInfo {
hasNextPage,
hasPreviousPage
}
},
id
}
If I run the same query without after
it will run successfully, even with a higher number of items
This is my (redacted) model structure:
ProductSchema = new mongoose.Schema({
name: { type: String, required: true,
},
attributes: { type: [{ type: ObjectId, ref: 'Attribute' }], index: true },
})..
Attribute = new mongoose.Schema({
name: {
type: 'String',
description: 'name of the attribute',
maxLength: 60,
required: true
})..
I'm using:
"@risingstack/graffiti": "^3.0.1",
"@risingstack/graffiti-mongoose": "^5.0.5",
"express": "^4.13.4",
"mongoose": "^4.3.7",
I am using express and mongoose, and I suspect many do.
It would nice to have an example of a graphiQL (https://github.com/graphql/graphiql) integration.
Is the graphQL schema exposed somewhere ?
Support sub-documents:
var childSchema = new Schema({ name: 'string' });
var parentSchema = new Schema({
children: [childSchema]
})
Have tried running the demo, and this query, as described in the docs, from the local graphql server:
mutation addX {
addUser(input: {name: "X", age: 11, clientMutationId: "1"}) {
id
name
}
}
returns an error:
{
"errors": [
{
"message": "Cannot query field \"id\" on \"addUserPayload\"."
},
{
"message": "Cannot query field \"name\" on \"addUserPayload\"."
}
]
}
while this query works fine:
mutation addX {
addUser(input: {name: "X", age: 11, clientMutationId: "1"}) {
changedUserEdge {
node {
id
name
}
}
}
}
So I wonder if the docs may be out of sync?
Feature request: Log queries to a database
What does following code from readme example means? How can we return from a module?
return yield graphql(schema, query);
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of memory
I'm constantly getting our of memory errors and my app crashes.
==== JS stack trace =========================================
Security context: 0x1991fcae3ac1
1: /* anonymous /(aka / anonymous /) [/usr/local/lib/node_modules/babel-cli/node_modules/core-js/modules/es6.promise.js:~67] [pc=0xc21e0f8675](this=0x1991fca04189 ,it=0x180c23cacaa9 <a Promise with map 0xcef15a14bc1)
2: / anonymous /(aka / anonymous */) [/usr/local/lib/node_modules/babel-cli/node_modules/core-js/modules/es6.promise.js:107] [pc=0xc221293e68] (this=0x19...
having described in my model images: [String]
when i attempt to save
images: [
"fc6092ab09574edd9cb82c665f97fb0b"
"c01a8ab7196e45c6981cb58f58152db6"
"3bcd62558a8a444ea9f1996efda062de"
"a23530eb3694408f8e8ef3a81fe3ceed"
"77dd890281ea4cd8b2cb4487c433dcdf"
]
in the database seems to save
"images": [
"e\u007f{}=\u001b",
"wM\\o\u001f\u001fgMyYVz",
"3bcd62558a8a444ea9f1996efda062de",
"a23530eb3694408f8e8ef3a81fe3ceed",
"77dd890281ea4cd8b2cb4487c433dcdf"
]
This doesn't seems to be consistently reproduceable but seems to happen only when the value of the string contains hashes (perhaps they get confused at times with ObjectId
?)
Hi,
I would like to know if there's a way (or if you're envisioning one) of having a custom resolve method for a specific field. For instance, imagine I've got a field that to be populated I must engage with a third party API or another database.
Best regards.
@hekike have you seen todays Relay release? You may be interested in middleware for express provided by FB team.
No matter what I try as a query, I get the following error in devtools (react.min.js):
Uncaught TypeError: Cannot read property 'getQueryType' of undefined
What do you think about removing lodash?
I am already using babel-node programmatically in my project. But babel-node doesn't go through node_modules. If I instruct it to do so, then it fails on an express middleware ("static is a reserved keyword").
It would make it easier to not require the use of babel
in the npm package.
If I have two schemas like this:
var personSchema = Schema({
name : String,
age : Number,
});
var storySchema = Schema({
_creator : { type: Schema.Types.ObjectId, ref: 'Person' },
title : String,
fans : [{ type: Schema.Types.ObjectId, ref: 'Person' }]
});
It would be nice to be able to add a connection from person to stories that results in Story.find({_creator:...})
Is there a way to specify the order of items returned by the server, e.g. { sort: { score: 1 } }
?
As far as I know, Relay and GraphQL have no concept of sorting. I was wondering if graffiti-mongoose allows adding the sort
parameter to the generated queries. Or maybe there is a way to build custom queries and attach them to auto-generated ones?
I'm trying to add a Slide to a Deck's array of Slides but I can't seem to find a mutation that works. Below is my Mongoose schema.
const DeckSchema = new mongoose.Schema({
name: {
type: String,
description: 'the full name of the deck'
},
slides: [{
type: mongoose.Schema.Types.ObjectId,
ref: 'Slide'
}]
});
const SlideSchema = new mongoose.Schema({
name: {
type: String,
description: 'the full name of the slide'
},
component: {
type: String,
description: 'name of slide component'
}
});
I'm not exactly sure whats going here here, but I installed graffiti-mongoose on my own user schema
var mongoose = require('mongoose'),
Schema = mongoose.Schema,
passportLocalMongoose = require('passport-local-mongoose')
var crypto = require('crypto')
var User = new Schema({
email: String,
unique_token: String,
angellist: {
data: Schema.Types.Mixed,
oauth_token: String,
refresh_token: String
},
google: {
data: Schema.Types.Mixed,
oauth_token: String,
refresh_token: String
}
})
In my expressjs server file I have this.
app.use(graffiti.express({
schema: getSchema([User])
}))
It appears that when I load graphql localhost:8080/graphql
graffiti is hanging on this line when the first introspection query is passed (38 in the published source):
`return (0, _coBody.json)(request).then(function (body) {`
The query body is this:
{ query: '\n query IntrospectionQuery {\n __schema {\n queryType { name }\n mutationType { name }\n types {\n ...FullType\n }\n directives {\n name\n description\n args {\n ...InputValue\n }\n onOperation\n onFragment\n onField\n }\n }\n }\n\n fragment FullType on __Type {\n kind\n name\n description\n fields {\n name\n description\n args {\n ...InputValue\n }\n type {\n ...TypeRef\n }\n isDeprecated\n deprecationReason\n }\n inputFields {\n ...InputValue\n }\n interfaces {\n ...TypeRef\n }\n enumValues {\n name\n description\n isDeprecated\n deprecationReason\n }\n possibleTypes {\n ...TypeRef\n }\n }\n\n fragment InputValue on __InputValue {\n name\n description\n type { ...TypeRef }\n defaultValue\n }\n\n fragment TypeRef on __Type {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n }\n }\n }\n }\n',
variables: null }
Any idea of what's going on?
Thanks,
Jon
I defined my models in different files using mongoose, when I try to import all of them I receive this erro:
Schema must contain unique named types but contains multiple types named
How can I get selectionSet
from fieldASTs with external fragment?
Consider following query
`
query QueryWithFragment {
todo(_id: "55a624bad009804e552eeea8") {
...TextFragment
}
}
fragment TextFragment on Todo {
text
}
`
This query results in
{
"kind": "Field",
"alias": null,
"name": {
"kind": "Name",
"value": "todo",
"loc": {
"start": 27,
"end": 31,
"source": {
"body": "\n query UseFragment {\n todo(_id: \"55a624bad009804e552eeea8\") {\n ...TextFragment\n }\n }\n\n fragment TextFragment on Todo {\n text\n }\n",
"name": "GraphQL request"
}
}
},
"arguments": [{
"kind": "Argument",
"name": {
"kind": "Name",
"value": "_id",
"loc": {
"start": 32,
"end": 35,
"source": {
"body": "\n query UseFragment {\n todo(_id: \"55a624bad009804e552eeea8\") {\n ...TextFragment\n }\n }\n\n fragment TextFragment on Todo {\n text\n }\n",
"name": "GraphQL request"
}
}
},
"value": {
"kind": "StringValue",
"value": "55a624bad009804e552eeea8",
"loc": {
"start": 37,
"end": 63,
"source": {
"body": "\n query UseFragment {\n todo(_id: \"55a624bad009804e552eeea8\") {\n ...TextFragment\n }\n }\n\n fragment TextFragment on Todo {\n text\n }\n",
"name": "GraphQL request"
}
}
},
"loc": {
"start": 32,
"end": 63,
"source": {
"body": "\n query UseFragment {\n todo(_id: \"55a624bad009804e552eeea8\") {\n ...TextFragment\n }\n }\n\n fragment TextFragment on Todo {\n text\n }\n",
"name": "GraphQL request"
}
}
}],
"directives": [],
"selectionSet": {
"kind": "SelectionSet",
"selections": [{
"kind": "FragmentSpread",
"name": {
"kind": "Name",
"value": "TextFragment",
"loc": {
"start": 76,
"end": 88,
"source": {
"body": "\n query UseFragment {\n todo(_id: \"55a624bad009804e552eeea8\") {\n ...TextFragment\n }\n }\n\n fragment TextFragment on Todo {\n text\n }\n",
"name": "GraphQL request"
}
}
},
"directives": [],
"loc": {
"start": 73,
"end": 88,
"source": {
"body": "\n query UseFragment {\n todo(_id: \"55a624bad009804e552eeea8\") {\n ...TextFragment\n }\n }\n\n fragment TextFragment on Todo {\n text\n }\n",
"name": "GraphQL request"
}
}
}],
"loc": {
"start": 65,
"end": 94,
"source": {
"body": "\n query UseFragment {\n todo(_id: \"55a624bad009804e552eeea8\") {\n ...TextFragment\n }\n }\n\n fragment TextFragment on Todo {\n text\n }\n",
"name": "GraphQL request"
}
}
},
"loc": {
"start": 27,
"end": 94,
"source": {
"body": "\n query UseFragment {\n todo(_id: \"55a624bad009804e552eeea8\") {\n ...TextFragment\n }\n }\n\n fragment TextFragment on Todo {\n text\n }\n",
"name": "GraphQL request"
}
}
}
Now lets take a look in InlineFragment version
`
query QueryWithoutFragment {
todo(_id: "55a624bad009804e552eeea8") {
... on Todo {
text
}
}
}
`
We can easily access requested fields for fragment in selectionSet
{
"kind": "Field",
"alias": null,
"name": {
"kind": "Name",
"value": "todo",
"loc": {
"start": 36,
"end": 40,
"source": {
"body": "\n query QueryWithoutFragment {\n todo(_id: \"55a624bad009804e552eeea8\") {\n ... on Todo {\n text\n }\n }\n }\n",
"name": "GraphQL request"
}
}
},
"arguments": [{
"kind": "Argument",
"name": {
"kind": "Name",
"value": "_id",
"loc": {
"start": 41,
"end": 44,
"source": {
"body": "\n query QueryWithoutFragment {\n todo(_id: \"55a624bad009804e552eeea8\") {\n ... on Todo {\n text\n }\n }\n }\n",
"name": "GraphQL request"
}
}
},
"value": {
"kind": "StringValue",
"value": "55a624bad009804e552eeea8",
"loc": {
"start": 46,
"end": 72,
"source": {
"body": "\n query QueryWithoutFragment {\n todo(_id: \"55a624bad009804e552eeea8\") {\n ... on Todo {\n text\n }\n }\n }\n",
"name": "GraphQL request"
}
}
},
"loc": {
"start": 41,
"end": 72,
"source": {
"body": "\n query QueryWithoutFragment {\n todo(_id: \"55a624bad009804e552eeea8\") {\n ... on Todo {\n text\n }\n }\n }\n",
"name": "GraphQL request"
}
}
}],
"directives": [],
"selectionSet": {
"kind": "SelectionSet",
"selections": [{
"kind": "InlineFragment",
"typeCondition": {
"kind": "Name",
"value": "Todo",
"loc": {
"start": 89,
"end": 93,
"source": {
"body": "\n query QueryWithoutFragment {\n todo(_id: \"55a624bad009804e552eeea8\") {\n ... on Todo {\n text\n }\n }\n }\n",
"name": "GraphQL request"
}
}
},
"directives": [],
"selectionSet": {
"kind": "SelectionSet",
"selections": [{
"kind": "Field",
"alias": null,
"name": {
"kind": "Name",
"value": "text",
"loc": {
"start": 104,
"end": 108,
"source": {
"body": "\n query QueryWithoutFragment {\n todo(_id: \"55a624bad009804e552eeea8\") {\n ... on Todo {\n text\n }\n }\n }\n",
"name": "GraphQL request"
}
}
},
"arguments": [],
"directives": [],
"selectionSet": null,
"loc": {
"start": 104,
"end": 108,
"source": {
"body": "\n query QueryWithoutFragment {\n todo(_id: \"55a624bad009804e552eeea8\") {\n ... on Todo {\n text\n }\n }\n }\n",
"name": "GraphQL request"
}
}
}],
"loc": {
"start": 94,
"end": 116,
"source": {
"body": "\n query QueryWithoutFragment {\n todo(_id: \"55a624bad009804e552eeea8\") {\n ... on Todo {\n text\n }\n }\n }\n",
"name": "GraphQL request"
}
}
},
"loc": {
"start": 82,
"end": 116,
"source": {
"body": "\n query QueryWithoutFragment {\n todo(_id: \"55a624bad009804e552eeea8\") {\n ... on Todo {\n text\n }\n }\n }\n",
"name": "GraphQL request"
}
}
}],
"loc": {
"start": 74,
"end": 122,
"source": {
"body": "\n query QueryWithoutFragment {\n todo(_id: \"55a624bad009804e552eeea8\") {\n ... on Todo {\n text\n }\n }\n }\n",
"name": "GraphQL request"
}
}
},
"loc": {
"start": 36,
"end": 122,
"source": {
"body": "\n query QueryWithoutFragment {\n todo(_id: \"55a624bad009804e552eeea8\") {\n ... on Todo {\n text\n }\n }\n }\n",
"name": "GraphQL request"
}
}
}
I'm currently working on conversion fieldASTs to MongoDB projections. I've done with InlineFragment. Any thoughts?
Hi, Thanks for this fantastic module.
However, when I do according to the example, I get an error. And I don't know why it errors.
The schema
const languageSchema = mongoose.Schema({
name: {
type: String,
validate: {
validator: function(v) {
return _.isString(v) && v.length;
},
message: 'Language name should be present.'
}
}
});
The query
mutation addLanguageJapanese {
addLanguage(input: {clientMutationId: "anyString", name: "Japanese"}) {
name, id
}
}
The response
{
"errors": [
{
"message": "Cannot query field \"name\" on \"addLanguagePayload\"."
},
{
"message": "Cannot query field \"id\" on \"addLanguagePayload\"."
}
]
}
Hi!
You mentioned in the docs:
You can add hooks to type fields and query fields (singular & plural queries, mutations) too. By passing arguments to the next function, you can modify the parameters of the next hook or the return value of the resolve function."
Curious what is meant by "passing arguments to the next function..." -- how does one make use of this functionality?
One example of what I'm trying to do is get access to the original mutation context object (the third argument to the pre hook) in the post hook. The reason for that is I want to introspect on the mutation that occurred to determine any side effects, but I want to do that AFTER the mutation is complete not before (where I have access to this information) Is there a simple way to do this via the next callback? Can I effectively pass that "through" to the post hook?
Not sure if this is irrelevant b/c future plans to support mongoose objects #4.
But currently the string type returned is invalid json. It appears the json returned has single quotes instead of doubles.
This (invalid JSON)
{"name':'search_term','description':'Company Name: Whole Foods','_id':'564d1f91f5e4c16a32d69376'}"
Compared to this (valid):
"{"name":"search_term","description":"Company Name: Whole Foods","_id":"564d1f91f5e4c16a32d69376"}"
If you point me to the right file, I can make a PR. Also, maybe I'm being silly, but wouldn't #4. be solved just by throwing this string into a JSON.parse() function?
I can do that as well if you would like.
Best,
Jon
In query.getList:
selector._id = {
$in: _id.map((id) => processId({id}))
};
_id is not an Array. It is actually { $gt: ... }
Option to able to exclude exposing fields to GraphQL.
I suggest to add links to commits in changelog.
The field hook example shows creation of a new model using mongoose.schema, how do I add field hooks to existing models?
Eg. If I want to format the a timestamp into 'x hours ago' string. Please see pseudo-code for what I'm trying to achieve:
var User = mongoose.model('User')
User._created.hooks = {
post: [
(next, date) => next(moment(date).fromNow())
]
}
var schema = getSchema([User])
I'm sure there's a way to do this, just struggling to get my head around hooks docs!
Thanks in advance :)
I am begginner with mongoose and graphql, and want ask to provide an example how add additional logic with graffiti-mongoose. For example:
{
me {
name
age
friends {
name
}
}
}
me
schema? According to the authorized user data in session I want obtain a current user profile.active friends
according to the session data? (Usual user can see only active friends
, admin can see any type of friends
.) For security reasons I can't allow to the client side do such query friends(active: true)
, it must be realized on the server side.Thanks.
hey, while running npm install i get the following error. do i have the wrong node version?
npm ERR! Linux 3.19.0-28-generic
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install"
npm ERR! node v5.2.0
npm ERR! npm v3.3.12
npm ERR! Invalid name: "@risingstack/graffiti-mongoose"
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR! <https://github.com/npm/npm/issues>
npm ERR! Please include the following file with any support request:
npm ERR! /home/mod-new/code/test/graffiti-mongoose/example/npm-debug.log
Hi,
Does this library support mongoose virtual fields ?
Need help with null values when using reference fields.
I have a NewsFeed
schema that contains a Product
, or a Post
, or a Video
. Defined as follows:
NewsFeed = new mongoose.Schema({
date: { type: Date, required: true, default: Date.now },
product: { type: ObjectId, ref: 'Product', required: false},
post: { type: ObjectId, ref: 'Post', required: false },
video: { type: ObjectId, ref: 'Post', required: false },
});
This means that aNewsFeed document contains a date and one element (one of product, post or video).
Ideally I what to use the GraphQL query bellow and fetch my newsfeed ordered by date and containing the applicable newsfeed element with the other elements absent or null.
query{
viewer{
homenewsfeeds(first:5,orderBy:DATE_DESC){
count,
edges{
node{
date,
product {
id,
name
},
post{
id,
title,
author {
id,
name
}
}
video{
id,
title,
duration,
}
}
}
}
}
}
However I get the following error:
"statusCode": 400,
"error": "Bad Request",
"message": "Cannot read property 'toString' of null\nCannot read property 'toString' of null\nCannot read property 'toString' of null\nCannot read property 'toString' of null\nCannot read property 'toString' of null"
My understating is that GraphQl is trying to load the referenced object even if is not in the current element.
I've already attempted to re-create the newsfeed forcing the elements to be required defaulting to null, with no success. I'm getting the same error
NewsFeed = new mongoose.Schema({
date: { type: Date, required: true, default: Date.now },
product: { type: ObjectId, ref: 'Product', required: true, default: null},
post: { type: ObjectId, ref: 'Post', required: true, default: null},
video: { type: ObjectId, ref: 'Post', required: true, default: null },
});
Another option would be refactor the NewsFeed as described bellow. However this will defeat the purpose of simpler GraphQL queries.
NewsFeed = new mongoose.Schema({
date: { type: Date, required: true, default: Date.now },
target: { type: ObjectId},
type: { type: String, enum: ['Post','Product','Video']},
});
Comments? This is a limitation of GraphQL or current Mongoose-GraphQl implementation?
It looks like the object ID returned in query is converted to GlobalId (by the graphql-relay since the globalIdField is used).
But in the mutation, the ID sent from the client is directly passed to the Mongo so some casting error will be reported. https://github.com/RisingStack/graffiti-mongoose/blob/master/src/schema/schema.js#L120
Will it be fixed in the framework, or should I handle it in the hooks?
Thanks
var PersonSchema = new Schema({
friends: {
type: [mongoose.Schema.Types.ObjectId],
ref: 'Person',
}
});
var EmployeeSchema = new Schema({
friends: {
type: [mongoose.Schema.Types.ObjectId],
ref: 'Employee',
}
});
This results in generating friendsConnection
twice.
N.B.: Moved this from RisingStack/graffiti#7
Just putting some thoughts down of currently missing features:
Relay wants to be able to (re-)fetch any object in the graph by a unique ID via a root query named node
:
node (id: "user123") {
id
name
}
Relay methods: fromGlobalId
/toGlobalId
See: https://github.com/relayjs/relay-starter-kit/blob/master/data/schema.js#L115
On the query side, relay requires first
and after
arguments (as well as last
and before
for backwards pagination):
users (first: 10, after: "user123") {
edges {
cursor
node {
id
name
}
}
pageInfo {
hasNextPage
}
}
edges
: describes the collection (https://facebook.github.io/relay/graphql/connections.htm#sec-Edge-Types)
cursor
: would be the unique ID discusses abovenode
: the box-standard field selectorpageInfo
: an object with meta-data about the current page (https://facebook.github.io/relay/graphql/connections.htm#sec-undefined.PageInfo)
hasNextPage
hasPreviousPage
: for backwards paginationAlso see: https://facebook.github.io/relay/graphql/connections.htm
TBC
I expect graphql-relay-js to help us out with the more intricate details
I hope we can work towards relay compatibility. Please let me know if this is more appropriate for an adapter, e.g. graffiti-mongoose
Hi.
I was looking for a way to order edges based on the parent document array, but couldn't find a way. For example, given a model with Person
and Destinations
and a database:
const destinations = [
new Destination({name: 'London'},
new Destination({name: 'Paris'},
new Destination({name: 'Berlin'}
];
const people = [
new Person({name: 'John', trips: [destinations[2], destinations[0]]}),
new Person({name: 'Jane', trips: [destinations[1]]}),
new Person({name: 'Jill', trips: [destinations[1], destinations[0]]})
];
and a query:
{
people {
name
trips {
edges {
node {
name
}
}
}
}
}
I would expect the result:
{
"data": {
"people": [
{
"name": "John",
"trips": {
"edges": [
{
"node": {
"name": "Berlin"
}
},
{
"node": {
"name": "London"
}
}
]
}
},
{
"name": "Jane",
"trips": {
"edges": [
{
"node": {
"name": "Paris"
}
}
]
}
},
{
"name": "Jill",
"trips": {
"edges": [
{
"node": {
"name": "Paris"
}
},
{
"node": {
"name": "London"
}
}
]
}
},
]
}
}
Is that currently possible with graffiti? I couldn't find a way to do it, nor to order in other collections. Thank you in advance for the attention!
I'm receiving this error on npm run coverage
ReferenceError: regeneratorRuntime is not defined
at /Users/sibelius/Dev/rturk/graffiti-mongoose/src/query/query.js:9:19199
For example I have model with required field:
import mongoose from 'mongoose';
const UserSchema = new mongoose.Schema({
email: {
type: String,
unique: true,
trim: true,
required: 'Email is required'
},
createdAt: {
type: Date,
default: Date.now
}
});
const User = mongoose.model('User', UserSchema);
export default User;
but when I send mutation to server like {"mutation { addUser(input: {clientMutationId: "1"}) { clientMutationId } }"}
I receive not well enough descriptive error:
{
"statusCode": 400,
"error": "Bad Request",
"message": "User validation failed"
}
Hi, I ran into this error
/Users/1/Developer/openv/node_modules/@risingstack/graffiti-mongoose/lib/query/query.js:351
var ref = _asyncToGenerator(regeneratorRuntime.mark(function _callee(graffitiModel, args, info) {
^
ReferenceError: regeneratorRuntime is not defined
The two orderBy
tests in e2e.spec.js
dont fail, if you switch NAME_DESC
to NAME_ASC
(and vice versa).
I noticed, that the actual Collection.find
call in query.js
gets called with
{
sort: 'NAME_DESC'
}
instead of
{
sort: { name: -1 }
}
It seems like the order keys somehow don't get resolved into the corresponding mongoose option.
If you can give me a bump in the right direction, I'd be happy to fix this.
It would be nice to add a sample query to the GraphiQL example when application starts.
getSchema returns a GraphQLSchema object based on MongooseModels, how do I go about adding my own types to this schema?
Consider the use case:
I have a Post
object with getLikedFriends
method, which looks up all Post.likes
references and queries Users
collection to check if any of the User.friends
references for the loggedIn user match with Post.likes
So instead of creating a new Mongoose model and re-implementing the logic inside my pre-existing getLikedFriends
method, I'd like to just add this as a new type to the GraphQL schema and let the resolve function call Post.getLikedFriends(ctx.loggedInUser)
This is something I can easily do using vanilla GraphQL but not sure how to augment the schema returned by graffiti :/
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.