Comments (11)
Hi @sulliwane,
you can save the user readable version of the schema to a file by using this script:
require('babel-polyfill');
const fs = require('fs');
const path = require('path');
const graffitiMongoose = require('@risingstack/graffiti-mongoose');
const graphqlUtils = require('graphql/utilities');
const mongooseSchema = require('./schema');
const schema = graffitiMongoose.getSchema(mongooseSchema);
// Save user readable type system shorthand of schema
fs.writeFileSync(
path.join(__dirname, './schema.graphql'),
graphqlUtils.printSchema(schema)
);
from graffiti-mongoose.
@tothandras I just tried your code, and I get this error:
/node_modules/@risingstack/graffiti-mongoose/lib/model/model.js:121
return mongooseModels.map(getModel).reduce(function (models, model) {
^
TypeError: mongooseModels.map is not a function
at getModels (/node_modules/@risingstack/graffiti-mongoose/lib/model/model.js:121:25)
at Object.getSchema (/node_modules/@risingstack/graffiti-mongoose/lib/schema/schema.js:260:45)
at Object.<anonymous> (/exportSchema.js:9:33)
at Module._compile (module.js:425:26)
at Object.Module._extensions..js (module.js:432:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:311:12)
at Function.Module.runMain (module.js:457:10)
at startup (node.js:136:18)
at node.js:972:3
I npm install [email protected]
, and also put require("babel-core/register");
at the top of your script as my schema use import
and it was not recognized.
I use node v5.
Any idea where the problem comes from? Is it related with babel 6? Thank you for you help
from graffiti-mongoose.
@sulliwane
You need to pass an array to the getSchema
function. In this case mongooseSchema
must be an array of mongoose models.
from graffiti-mongoose.
ok, it works now! awsome. Relay compatibility layer is still black magic though, so I need to take some time to make sense out of it...thanks!
from graffiti-mongoose.
@sulliwane take a look at graffiti-todo!
from graffiti-mongoose.
@sulliwane also :) https://blog.risingstack.com/graffiti-mongoose-mongodb-for-graphql/
from graffiti-mongoose.
@tothandras awesome, thanks for the notification :)
from graffiti-mongoose.
hi tothandras, When exporting the graphql.schema file using graffiti-mongoose and your script, the file is not written in plain javascript. It's graphql syntax I guess. Is there any way to export a javascript version? Also, where are the resolve functions in this file? (replaced by resolve-hooks?)
trying to understand what's going on... Thanks
from graffiti-mongoose.
@sulliwane I am not sure what do you mean "javascript" version. :) You can print it out as it is if you like, but looking at the source code would make more sense.
You can find a resolve
function on every query, mutation and field. Take a look at the source code or the graphql-js documentation.
from graffiti-mongoose.
this is what it looks like when exported using graffiti-mongoose:
input addCardInput {
title: String
description: String
clientMutationId: String!
}
type addCardPayload {
viewer: Viewer
changedCardEdge: changedCardEdge
clientMutationId: String!
}
type Card implements Node {
title: String
description: String
_id: ID
id: ID!
}
and this is what my schema looks like ("javascript"):
const Query = new GraphQLObjectType({
name: 'RootQuery',
fields: () => ({
hello: {
type: GraphQLString,
resolve() {return 'world';}
},
});
const Schema = new GraphQLSchema({
query: Query,
mutation: Mutation
});
export default Schema;
I need to read more about graphql, I may not be using it the right way...
from graffiti-mongoose.
@sulliwane It's calling a lot of constructors as you can see, I am pretty sure you can't view it as it is.
from graffiti-mongoose.
Related Issues (20)
- Implicit dependency on babel-polyfill HOT 9
- Cannot set currently-valued fields to null in update mutation HOT 2
- How to make a custom field: id? HOT 10
- "TypeError: Cannot read property 'forEach' of undefined" when embedded object field is a reference HOT 6
- Custom query thunk - accepts only InputObject types HOT 3
- Question on customQueries HOT 7
- Example project doesnt work with [email protected] and [email protected] HOT 1
- Async hook support HOT 2
- How to use Express Middleware for Authentication/Authorization. HOT 4
- Get specific field validation error?
- How to mutate nested Schema? HOT 3
- What is different between id and _id HOT 1
- UNMET PEER DEPENDENCY HOT 1
- Maintainer Volunteer Thread HOT 1
- Mongoose ObjectId and GraphQL id is not the same. How to link them? HOT 5
- It is possible to add some description to schema and to be reflected in the docs?
- Does graffiti-mongoose works with react-apollo ? HOT 2
- Custom mutations?
- Custom queries/mutations HOT 1
- setTypeFields bug
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graffiti-mongoose.