format-graphql icon indicating copy to clipboard operation
format-graphql copied to clipboard

Add support for schema extensions

Open tomfa opened this issue 2 years ago • 0 comments

When running the formatter against schemas with extension, the following error is displayed:

***/app/node_modules/format-graphql/dist/utilities/formatSdl.js:30
      return a.name.value.localeCompare(b.name.value);
                                               ^

TypeError: Cannot read properties of undefined (reading 'value')
    at ***/app/node_modules/format-graphql/dist/utilities/formatSdl.js:30:48
    at Array.sort (<anonymous>)
    at sortSchema (***/app/node_modules/format-graphql/dist/utilities/formatSdl.js:20:26)
    at walkAST (***/app/node_modules/format-graphql/dist/utilities/formatSdl.js:83:15)
    at formatSdl (***/app/node_modules/format-graphql/dist/utilities/formatSdl.js:90:30)
    at Object.<anonymous> (***/app/node_modules/format-graphql/dist/bin/index.js:52:44)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
error Command failed with exit code 1.

Example schema:

extend schema @link(url: "https://specs.apollo.dev/federation/v2.0", import: ["@key", "@shareable"])

type GenericResponse @shareable {
  message: String
  success: Boolean!
}

tomfa avatar May 05 '22 07:05 tomfa