How to use @gatsbyjs/relay-compiler - 5 common examples

To help you get started, we’ve selected a few @gatsbyjs/relay-compiler examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gatsbyjs / gatsby / packages / gatsby / src / query / query-compiler.js View on Github external
})
        return compiledNodes
      }

      documents.push(doc)
      doc.definitions.forEach((def: any) => {
        const name: string = def.name.value
        namePathMap.set(name, filePath)
        nameDefMap.set(name, def)
      })
    }

    let compilerContext = new GraphQLCompilerContext(this.schema)
    try {
      compilerContext = compilerContext.addAll(
        ASTConvert.convertASTDocuments(
          this.schema,
          documents,
          validationRules,
          RelayParser.transform.bind(RelayParser)
        )
      )
    } catch (error) {
      const { formattedMessage, docName, message, codeBlock } = graphqlError(
        namePathMap,
        nameDefMap,
        error
      )
      nameErrorMap.set(docName, { formattedMessage, message, codeBlock })
      boundActionCreators.queryExtractionGraphQLError({
        componentPath: namePathMap.get(docName),
        error: formattedMessage,
github gatsbyjs / gatsby / packages / gatsby / src / query / query-compiler.js View on Github external
this.reportError(graphqlValidationError(errors, filePath))
        boundActionCreators.queryExtractionGraphQLError({
          componentPath: filePath,
        })
        return compiledNodes
      }

      documents.push(doc)
      doc.definitions.forEach((def: any) => {
        const name: string = def.name.value
        namePathMap.set(name, filePath)
        nameDefMap.set(name, def)
      })
    }

    let compilerContext = new GraphQLCompilerContext(this.schema)
    try {
      compilerContext = compilerContext.addAll(
        ASTConvert.convertASTDocuments(
          this.schema,
          documents,
          validationRules,
          RelayParser.transform.bind(RelayParser)
        )
      )
    } catch (error) {
      const { formattedMessage, docName, message, codeBlock } = graphqlError(
        namePathMap,
        nameDefMap,
        error
      )
      nameErrorMap.set(docName, { formattedMessage, message, codeBlock })
github gatsbyjs / gatsby / packages / gatsby / src / query / query-compiler.js View on Github external
this.reportError(
          multipleRootQueriesError(
            filePath,
            nameDefMap.get(name),
            otherNode && nameDefMap.get(otherNode.name)
          )
        )
        boundActionCreators.queryExtractionGraphQLError({
          componentPath: filePath,
        })
        return
      }

      let text = filterContextForNode(printContext.getRoot(name), printContext)
        .documents()
        .map(GraphQLIRPrinter.print)
        .join(`\n`)

      const query = {
        name,
        text,
        originalText: nameDefMap.get(name).text,
        path: filePath,
        isHook: nameDefMap.get(name).isHook,
        isStaticQuery: nameDefMap.get(name).isStaticQuery,
        hash: nameDefMap.get(name).hash,
      }

      if (query.isStaticQuery) {
        query.id =
          `sq--` +
          _.kebabCase(
github gatsbyjs / gatsby / packages / gatsby / src / query / query-compiler.js View on Github external
documents.push(doc)
      doc.definitions.forEach((def: any) => {
        const name: string = def.name.value
        namePathMap.set(name, filePath)
        nameDefMap.set(name, def)
      })
    }

    let compilerContext = new GraphQLCompilerContext(this.schema)
    try {
      compilerContext = compilerContext.addAll(
        ASTConvert.convertASTDocuments(
          this.schema,
          documents,
          validationRules,
          RelayParser.transform.bind(RelayParser)
        )
      )
    } catch (error) {
      const { formattedMessage, docName, message, codeBlock } = graphqlError(
        namePathMap,
        nameDefMap,
        error
      )
      nameErrorMap.set(docName, { formattedMessage, message, codeBlock })
      boundActionCreators.queryExtractionGraphQLError({
        componentPath: namePathMap.get(docName),
        error: formattedMessage,
      })
      this.reportError(formattedMessage)
      return false
    }
github gatsbyjs / gatsby / packages / gatsby / src / query / query-compiler.js View on Github external
if (compiledNodes.has(filePath)) {
        let otherNode = compiledNodes.get(filePath)
        this.reportError(
          multipleRootQueriesError(
            filePath,
            nameDefMap.get(name),
            otherNode && nameDefMap.get(otherNode.name)
          )
        )
        boundActionCreators.queryExtractionGraphQLError({
          componentPath: filePath,
        })
        return
      }

      let text = filterContextForNode(printContext.getRoot(name), printContext)
        .documents()
        .map(GraphQLIRPrinter.print)
        .join(`\n`)

      const query = {
        name,
        text,
        originalText: nameDefMap.get(name).text,
        path: filePath,
        isHook: nameDefMap.get(name).isHook,
        isStaticQuery: nameDefMap.get(name).isStaticQuery,
        hash: nameDefMap.get(name).hash,
      }

      if (query.isStaticQuery) {
        query.id =