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: Unknown directive "@entity" #79

Open
pandichef opened this issue Aug 3, 2021 · 1 comment
Open

Error: Unknown directive "@entity" #79

pandichef opened this issue Aug 3, 2021 · 1 comment

Comments

@pandichef
Copy link

pandichef commented Aug 3, 2021

I'm using thegraph.com's schema convention e.g., https://thegraph.com/docs/developer/create-subgraph-hosted#good-example. My schema looks like this:

type Item @entity {
  id: ID!
  var1: BigInt!
  var2: BigInt!
  name: String!
}

I get this error when I run npx graphql-markdown schema.graphql schema.md:

Error: Unknown directive "@entity".
Unknown type "BigInt". Did you mean "Int"?

Can this tool accommodate or should I look elsewhere for a solution? Ty

@wagnerlduarte
Copy link

Hey @pandichef! This problem happen because the graphql-markdown use the graphql to generate de markdown file. So, it need the typeDefs and directives to works well.

Do you need to include in your .graphql file these definitions manually how do you can see here, or make it programatically.

const { execSync } = require('child_process')
const fs = require('fs')

const argv = require('minimist')(process.argv.slice(2))
const { yourTypeDefs } = require('your-package')
const graphql = require('graphql')
const { loadFilesSync } = require('@graphql-tools/load-files')
const { makeExecutableSchema } = require('@graphql-tools/schema')
const { mergeTypeDefs } = require('@graphql-tools/merge')
const { stitchingDirectives } = require('@graphql-tools/stitching-directives')

const { allStitchingDirectivesTypeDefs } = stitchingDirectives()

const DEFAULT_GRAPHQL_PATH = './graphql/**/*.{gql,graphql}'
const DEFAULT_MERGED_PATH = './merged.graphql'
const DEFAULT_MARKDOWN_PATH = './schema.md'

const GRAPHQL_ARG = argv['graphql-path']
const MERGED_ARG = argv['merged-path']
const MARKDOWN_ARG = argv['markdown-path']

const GRAPHQL_PATH = GRAPHQL_ARG || DEFAULT_GRAPHQL_PATH
const MERGED_PATH = MERGED_ARG || DEFAULT_MERGED_PATH
const MARKDOWN_PATH = MARKDOWN_ARG || DEFAULT_MARKDOWN_PATH

const loadedFiles = loadFilesSync(GRAPHQL_PATH)

const typeDefs = mergeTypeDefs(loadedFiles)

const schema = makeExecutableSchema({
  typeDefs: [allStitchingDirectivesTypeDefs, typeDefs, yourTypeDefs],
})

const printedSchema = graphql.printSchema(schema)

fs.writeFileSync(MERGED_PATH, printedSchema)

execSync(
  `graphql-markdown ${MERGED_PATH} > ${MARKDOWN_PATH} && rm ${MERGED_PATH}`
)

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

2 participants