File tree Expand file tree Collapse file tree 2 files changed +10
-3
lines changed Expand file tree Collapse file tree 2 files changed +10
-3
lines changed Original file line number Diff line number Diff line change 1717 "node" : " >=9.11.2"
1818 },
1919 "devDependencies" : {
20+ "dataloader-sequelize" : " ^1.7.6" ,
2021 "eslint" : " ^4.16.0" ,
2122 "eslint-config-standard" : " ^11.0.0-beta.0" ,
2223 "eslint-plugin-import" : " ^2.8.0" ,
2324 "eslint-plugin-node" : " ^5.2.1" ,
2425 "eslint-plugin-promise" : " ^3.6.0" ,
2526 "eslint-plugin-standard" : " ^3.0.1" ,
26- "dataloader-sequelize" : " ^1.7.6" ,
2727 "express" : " ^4.16.4" ,
2828 "graphql" : " ^14.0.2" ,
2929 "graphql-relay" : " ^0.5.5" ,
Original file line number Diff line number Diff line change 11const { GraphQLList, GraphQLString, GraphQLInt } = require ( 'graphql' )
22const { attributeFields } = require ( 'graphql-sequelize' )
33const createResolver = require ( '../createResolver' )
4+ const debug = require ( 'debug' ) ( 'gsg' )
45
56const generateAssociationField = ( relation , types , resolver = null ) => {
67 const type =
@@ -67,18 +68,24 @@ const injectAssociations = (
6768 proxyModelName = null
6869) => {
6970 const modelName = proxyModelName || modelType . name
71+ if ( Object . keys ( modelName ) . length === 0 ) {
72+ throw new Error (
73+ 'Associations cannot be injected if no models were provided.'
74+ )
75+ }
7076 const associations = models [ modelName ] . associations
7177 if ( Object . keys ( associations ) . length === 0 ) {
7278 return modelType
7379 }
7480 const associationsFields = { }
7581 for ( let associationName in associations ) {
7682 if ( ! graphqlSchemaDeclaration [ associations [ associationName ] . target . name ] ) {
77- throw new Error (
83+ debug (
7884 `Cannot generate the association for model [${
7985 associations [ associationName ] . target . name
80- } ] as it wasn't declared in the schema declaration.`
86+ } ] as it wasn't declared in the schema declaration. Skipping it. `
8187 )
88+ continue
8289 }
8390 associationsFields [ associationName ] = generateAssociationField (
8491 associations [ associationName ] ,
You can’t perform that action at this time.
0 commit comments