Coder Social home page Coder Social logo

Comments (11)

tothandras avatar tothandras commented on July 19, 2024

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.

sulliwane avatar sulliwane commented on July 19, 2024

@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.

tothandras avatar tothandras commented on July 19, 2024

@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.

sulliwane avatar sulliwane commented on July 19, 2024

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.

tothandras avatar tothandras commented on July 19, 2024

@sulliwane take a look at graffiti-todo!

from graffiti-mongoose.

tothandras avatar tothandras commented on July 19, 2024

@sulliwane also :) https://blog.risingstack.com/graffiti-mongoose-mongodb-for-graphql/

from graffiti-mongoose.

sulliwane avatar sulliwane commented on July 19, 2024

@tothandras awesome, thanks for the notification :)

from graffiti-mongoose.

sulliwane avatar sulliwane commented on July 19, 2024

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.

tothandras avatar tothandras commented on July 19, 2024

@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.

sulliwane avatar sulliwane commented on July 19, 2024

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.

tothandras avatar tothandras commented on July 19, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.