Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
andrejsarafimovski committed Aug 1, 2022
1 parent 686bc6c commit b5210ac
Show file tree
Hide file tree
Showing 8 changed files with 4,626 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
16 changes: 16 additions & 0 deletions .graphql-schema-linterrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"rules": [
"descriptions-are-capitalized",
"enum-values-all-caps",
"fields-are-camel-cased",
"fields-have-descriptions",
"types-have-descriptions",
"defined-types-are-used",
"deprecations-have-a-reason",
"input-object-fields-sorted-alphabetically",
"interface-fields-sorted-alphabetically",
"type-fields-sorted-alphabetically",
"types-are-capitalized",
"enum-values-sorted-alphabetically"
]
}
25 changes: 23 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,23 @@
# action-graphql-linter
Custom GitHub Action for linting GraphQL
# GraphQL Linter Action

This action lints the GraphQL Schemas sent in the input.

## Inputs

## `graphql-schemas`

**Required** GraphQL Schemas to lint.

## Example usage

```yaml
uses: actions/[email protected]
with:
graphql-schemas: 'app/graphql.schema'
```
```yaml
uses: actions/[email protected]
with:
graphql-schemas: 'graphql1.schema,graphql2.schema'
```
9 changes: 9 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: 'GraphQL Linter'
description: 'Lints the given GraphQL schemas'
inputs:
files:
description: 'Files to lint'
required: true
runs:
using: 'node16'
main: 'index.js'
34 changes: 34 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const core = require('@actions/core');
const github = require('@actions/github');
const { runner } = require('graphql-schema-linter');

function lintSchemas(schemas) {
const args = [null, __dirname, ...schemas];
console.log("Linting schemas: ", schemas.join())
return runner.run(process.stdout, process.stdin, process.stderr, args)
}
async function main() {
const payload = JSON.stringify(github.context.payload, undefined, 2)
console.log(`The event payload: ${payload}`);
try {
const schemaFiles = core.getInput('files').split(',');
const combined = core.getInput('combined');

if (combined) {
const exitCode = await lintSchemas(schemaFiles);
if (exitCode !== 0) {
throw new Error(`Invalid Schemas ${schemas}`);
}
} else {
for (const schema of schemaFiles) {
const exitCode = await lintSchemas([schema]);
if (exitCode !== 0) {
throw new Error(`Invalid Schema ${schema}`);
}
}
}
} catch (error) {
core.setFailed(error.message);
}
}
main();
12 changes: 12 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "playground",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"@actions/core": "^1.9.0",
"@actions/github": "^5.0.3",
"graphql": "^16.5.0",
"graphql-schema-linter": "^3.0.1"
}
}
Loading

0 comments on commit b5210ac

Please sign in to comment.