| 244 | } |
| 245 | |
| 246 | _createItem(operation, data) { |
| 247 | if (!this.factories[operation]) { |
| 248 | throw new Error(`Mutation ${operation} is not defined in config.factories`) |
| 249 | } |
| 250 | let modulePath = this.factories[operation].factory |
| 251 | try { |
| 252 | try { |
| 253 | require.resolve(modulePath) |
| 254 | } catch (e) { |
| 255 | modulePath = path.join(store.codeceptDir, modulePath) |
| 256 | } |
| 257 | const builder = require(modulePath) |
| 258 | return builder.build(data) |
| 259 | } catch (err) { |
| 260 | throw new Error(`Couldn't load factory file from ${modulePath}, check that |
| 261 | |
| 262 | "factories": { |
| 263 | "${operation}": { |
| 264 | "factory": "./path/to/factory" |
| 265 | |
| 266 | points to valid factory file. |
| 267 | Factory file should export an object with build method. |
| 268 | |
| 269 | Current file error: ${err.message}`) |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | /** |
| 274 | * Executes request to create a record to the GraphQL endpoint. |