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

Error with relative paths inside sdl #10

Open
peterpetre opened this issue Apr 18, 2018 · 6 comments
Open

Error with relative paths inside sdl #10

peterpetre opened this issue Apr 18, 2018 · 6 comments

Comments

@peterpetre
Copy link

Error, no such file or directory:
# import * from './myFolder/myFile.graphql'

Ok, with absolute paths:
# import * from 'src/.../myFolder/myFile.graphql'

I didnt meet any problem like this with graphql-import.

I just saw that on the documentation you have absolute paths, but what blocks to have the same behavior with the loader?

@JinHoSo
Copy link

JinHoSo commented May 16, 2018

+1

@dsanch3z
Copy link

dsanch3z commented Oct 5, 2018

Maybe it's related to the graphql-import version that's being used?

"dependencies": {
    "graphql-import": "^0.4.5"
},

@RoryKelly
Copy link

+1

@ThisIsMissEm
Copy link

Nope, it's actually a bug in https://github.com/prisma/graphql-import-loader/blob/master/src/index.ts#L8

It should be this.resource rather than source, as source is the file contents, which means that graphql-import doesn't have context of the location of the schema; If you pass importSchema(schema, [schemas]) a schema argument of type string which ends with ".graphql" then it does the file loading instead, which means all your imports get resolved to that file; without it, it's just from the root of your project.

@ThisIsMissEm
Copy link

(addendum: I just decided to switch to webpack-graphql-loader, which works roughly similar, but not as advanced on imports (it's more or less just file concatenation).

leosuncin added a commit to leosuncin/graphql-import-loader that referenced this issue Jan 28, 2019
Use the file path instead of file content to import schema. Set Jest's environment to node
to avoid the error with jsdom's localStorage, see jestjs/jest#6766 and jsdom/jsdom#2304.

BREAKING CHANGE: Use absolute path inside DSL won't work anymore, but now will be the same
behavior of `graphql-import` dealing with paths.

Fix prisma-labs#10
@jgeschwendt
Copy link
Contributor

This is a possible fix, it also adds all the files to webpack's watch mode:

import { importSchema, parseSDL } from 'graphql-import'
import { dirname, resolve } from 'path'

export default function (source) {
  const callback = this.async()

  this.cacheable()

  parseSDL(source).forEach(rawModule => {
    this.addDependency(resolve(dirname(this.resourcePath), rawModule.from))
  })

  callback(null, `module.exports = \`${importSchema(this.resourcePath).replace(/`/g, '\\`')}\``)
}

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

6 participants