Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not sure if an issue or maybe something I'm not getting: #133

Closed
oviava opened this issue Feb 1, 2016 · 3 comments
Closed

Not sure if an issue or maybe something I'm not getting: #133

oviava opened this issue Feb 1, 2016 · 3 comments

Comments

@oviava
Copy link

oviava commented Feb 1, 2016

module.exports = (sequelize, DataTypes) => {
  let Speaker = sequelize.define('Speaker', { // eslint-disable-line
    name: { type: DataTypes.STRING(128), allowNull: false }, // eslint-disable-line
    description: DataTypes.STRING,
    position: DataTypes.STRING(128), // eslint-disable-line
    company: DataTypes.STRING(128), // eslint-disable-line
  }, {
    classMethods: {
      associate: (models) => {
        Speaker.Presentations = Speaker.hasMany(models.Presentation, { as: 'presentations' });
      },
    },
  });

  return Speaker;
};
module.exports = (sequelize, DataTypes) => {
  const Presentation = sequelize.define('Presentation', {
    title: { type: DataTypes.STRING(128), allowNull: false }, // eslint-disable-line
    description: DataTypes.STRING,
  }, {
    classMethods: {
      associate: (models) => {
        Presentation.Speaker = Presentation.belongsTo(models.Speaker, {
          as: 'speaker',
          foreignKey: 'speakerId',
          onDelete: 'CASCADE',
        });
      },
    },
  });

  return Presentation;
};
'use strict';

const fs = require('fs');
const path = require('path');
const Sequelize = require('sequelize');
const sequelize = new Sequelize('xxxxx', 'xxxxx', 'xxxxx', {
  host: 'localhost',
  dialect: 'mariadb',
});

let db = {};

fs
  .readdirSync(__dirname)
  .filter((file) => (file.indexOf('.') !== 0) && (file !== 'index.js'))
  .forEach((file) => {
    const model = sequelize.import(path.join(__dirname, file));
    db[model.name] = model;
  });

Object.keys(db).forEach((modelName) => {
  if ('associate' in db[modelName]) {
    db[modelName].associate(db);
  }
});

db.sequelize = sequelize;
db.Sequelize = Sequelize;

module.exports = db;
import { resolver } from 'graphql-sequelize';
import {
  GraphQLObjectType,
  GraphQLNonNull,
  GraphQLString,
  GraphQLInt,
} from 'graphql';

import { Presentation } from '../models';
import speakerType from './speakerType';


const presentationType = new GraphQLObjectType({
  name: 'Presentation',
  description: 'A Presentation',
  fields: {
    id: {
      type: new GraphQLNonNull(GraphQLInt),
      description: 'Presentation Id',
    },
    title: {
      type: new GraphQLNonNull(GraphQLString),
      description: 'Presentation Title',
    },
    description: {
      type: GraphQLString,
      description: 'Presentation Description',
    },
    speaker: {
      type: speakerType,
      resolve: resolver(Presentation.Speaker),
    },
  },
});

export default presentationType;

error:

Error: Presentation.speaker field type must be Output Type but got: undefined.

Can't seem to get references to work

@mickhansen
Copy link
Owner

The resolver is not your issue, the type for speaker is undefined, try logging speakerType

@oviava
Copy link
Author

oviava commented Feb 1, 2016

think I found it ... just assumed that was ok:

https://gist.github.com/xicombd/77406c29ddf37fe46c3c

@oviava
Copy link
Author

oviava commented Feb 1, 2016

Closed. Thank you Mick, fyi for anyone else who might encounter this.

@oviava oviava closed this as completed Feb 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants