question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Github action: Allow globs in schema

See original GitHub issue

Is your feature request related to a problem? Please describe.

Often graphql schema’s are split in multiple files.

Describe the solution you’d like Allow to specify the schema using a glob as in schema: main:api/**/*.graphql.

Describe alternatives you’ve considered

Currently, globs are not supported as the above schema leads to the following error:

Error: ENOENT: no such file or directory, open '/home/runner/work/JabRefOnline/JabRefOnline/api/**/*.graphql'
Query main:api/**/*.graphql from JabRef/JabRefOnline
{ repository: { object: null } }
Error: result.repository.object.text is null
    at /home/runner/work/_actions/kamilkisiela/graphql-inspector/v2.6.2/action/index.js:1:357422
    at Generator.next (<anonymous>)
    at fulfilled (/home/runner/work/_actions/kamilkisiela/graphql-inspector/v2.6.2/action/index.js:1:254624)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)

It would be also nice if the schema could automatically be picked up from a graphql.config file.

Additional context

Moreover, the schema field is not documented.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:2
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
prescottpruecommented, Mar 24, 2022

If your are usingendpoint as a base (assuming you don’t want to git track a combined schema file) then you can merge your schema files into one using a simple script:

bin/combine-graphql-files.js

const { mergeTypeDefs } = require('@graphql-tools/merge');
const { loadFilesSync } = require('@graphql-tools/load-files');
const { print } = require('graphql');
const { writeFileSync } = require('fs');

const typeDefs = mergeTypeDefs(loadFilesSync(`${process.cwd()}/src/**/*.graphql`));
writeFileSync(`${process.cwd()}/combined.graphql`, print(typeDefs))

Then in call it right before in your workflow and reference the file in graphql-inspector step:

      - name: Combine .graphql files for validation
        run: node bin/combine-graphql-files.js

      - name: Validate graph changes
        uses: kamilkisiela/graphql-inspector@master
        with:
          schema: 'combined.graphql'
          endpoint: 'https://yousite.com/graphql
Or if you prefer inline instead of referencing a file
      - name: Combine .graphql files (typedefs) for validation
        uses: actions/github-script@v6
        with:
          script: |
            const { mergeTypeDefs } = require('@graphql-tools/merge');
            const { loadFilesSync } = require('@graphql-tools/load-files');
            const { print } = require('graphql');
            const { writeFileSync } = require('fs');

            const typeDefs = mergeTypeDefs(loadFilesSync(`${process.cwd()}/src/**/*.graphql`));
            writeFileSync(`${process.cwd()}/combined.graphql`, print(typeDefs))

      - name: Validate graph changes
        uses: kamilkisiela/graphql-inspector@master
        with:
          schema: 'combined.graphql'
          endpoint: 'https://yousite.com/graphql
1reaction
jayzescommented, Mar 24, 2022

If it helps, here’s a sample config from one of our repos that merges multiple schema files together across different branches using two different checkout steps:

name: GraphQL Inspector
on:
  pull_request:
    paths:
      - 'api/**.gql'
jobs:
  check-schema:
    name: Check Schema for Breaking Changes
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Base Commit
        uses: actions/checkout@v2
        with:
          ref: ${{ github.event.pull_request.base.sha }}
          path: base_tree

      - name: Checkout PR Commit
        uses: actions/checkout@master
        with:
          path: pr_tree

      - uses: ruby/setup-ruby@v1
        with:
          ruby-version: 2.7
          bundler-cache: true
          working-directory: pr_tree

      - name: Compare Schema
        id: compare
        continue-on-error: true
        shell: bash {0}
        working-directory: pr_tree/ruby
        run: |
          oldSchema=$(cat ../../base_tree/api/*.gql)
          newSchema=$(cat ../api/*.gql)
          compareOutput="$(bundle exec schema_comparator verify "$oldSchema" "$newSchema" 2>&1)"
          compareExit=$?
          # https://github.community/t/set-output-truncates-multiline-strings/16852/3
          compareOutput="${compareOutput//'%'/'%25'}"
          compareOutput="${compareOutput//$'\n'/'%0A'}"
          compareOutput="${compareOutput//$'\r'/'%0D'}"
          echo "::set-output name=stdout::$compareOutput"
          exit $compareExit

      - uses: hasura/comment-progress@v2
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          repository: ${{ github.repository }}
          number: ${{ github.event.number }}
          id: gql-changes
          recreate: true
          message: |
            ### GraphQL Changes Summary
            ```
            ${{steps.compare.outputs.stdout}}
            ```

It’s currently using https://github.com/xuorig/graphql-schema_comparator but could easily be modified to use graphql-inspector instead (using the snippet above I think). In our repo structure, schema files live in an api folder under the root.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Workflow syntax for GitHub Actions
The branches and branches-ignore keywords accept glob patterns that use characters like * , ** , + , ? , ! and others...
Read more >
GitHub Actions CI Conditional Regex - Stack Overflow
I'm trying to move my CI workflow from CircleCI to GitHub Actions. The last major struggle I'm facing is with deployment.
Read more >
Building Your First GitHub Action - Azure DevOps Blog
The action we build in this guide will make it easy to upload files to Azure Blob Storage, a service for massively scalable...
Read more >
Intellisense for your GitHub Actions workflows - Patrik Svensson
Today I found out that there is a JSON schema for GitHub Actions over at json.schemastore.org, and that means that we can use...
Read more >
yaml-language-server - npm
schemaStore.enable : When set to true the YAML language server will ... We use a GitHub Action to publish each change in the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found