Mayank1791989 / gql

112 stars 19 forks source link

Ignore node_modules by default or provide example ignoring node_modules #172

Open ryardley opened 4 years ago

ryardley commented 4 years ago

When I first configured gql I found errors in the output console in vscode and had to work out what was happening. I was also getting a bunch of weird errors where linting was complaining about duplicate Query and Mutation types. It turned out gql was scanning all node_modules folders in my monorepo which brought up a tone of errors.

It would save a bit of hassle and compute cycles if gql ignored all nested node_modules folders by default. Maybe there are situations where this is not desired but I would imagine most people don't need to validate graphql files in their node_modules.

Alternatively simply updating the docs to demonstrate that it is probably a good idea to ignore node_modules as a sensible starting point would be fine too.

I am sure this can be tightened up but my config I have settled on so far looks something like this:

{
  schema: {
    files: { include: "**/schema.graphql", ignore: "**/node_modules/**/*" }
  },
  query: {
    files: [
      {
        match: {
          include: ["**/*.ts", "**/*.tsx"],
          ignore: "**/node_modules/**/*"
        },
        parser: ["EmbeddedQueryParser", { startTag: "gql`", endTag: "`" }]
      },
      {
        match: {
          include: "**/*.graphql",
          ignore: "**/node_modules/**/*"
        },
        parser: "QueryParser"
      }
    ]
  }
}