Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/everlastingbugstopper/awc

lib/cli/web wrappers for apollo-compiler (GraphQL)
https://github.com/everlastingbugstopper/awc

compiler graphql rust

Last synced: 27 days ago
JSON representation

lib/cli/web wrappers for apollo-compiler (GraphQL)

Awesome Lists containing this project

README

        

# awc (apollo-web-compiler)

This project runs [`apollo-compiler`](https://github.com/apollographql/apollo-rs) on GraphQL schemas as a service.

## Usage

There are many ways to use `awc`. None of them are particularly stable.

### Run the CLI

1) Install [rustup](https://rustup.rs)
1) Get a [GraphQL Schema](./schemas/prod.graphql) and save it to `document.graphql`
1) Clone this repo.
1) Run the following:

```console
$ cargo awc lint --schema ./schemas/cat.graphql --watch
Finished dev [unoptimized + debuginfo] target(s) in 0.12s
Running `target/debug/awc-cli lint --schema ./schemas/cat.graphql --watch`
๐Ÿ“š reading ./schemas/cat.graphql from disk
apollo-compiler validation error

ร— cannot find type `Cat` in this document
โ•ญโ”€[36:1]
36 โ”‚
37 โ”‚ union Pet = Cat | Dog
ยท โ”€โ”€โ”ฌโ”€
ยท โ•ฐโ”€โ”€ not found in this scope
โ•ฐโ”€โ”€โ”€โ”€

apollo-compiler validation error

ร— cannot find type `Dog` in this document
โ•ญโ”€[36:1]
36 โ”‚
37 โ”‚ union Pet = Cat | Dog
ยท โ”€โ”ฌโ”€
ยท โ•ฐโ”€โ”€ not found in this scope
โ•ฐโ”€โ”€โ”€โ”€

apollo-compiler validation error

ร— cannot find type `Result` in this document
โ•ญโ”€[33:1]
33 โ”‚ type Subscription {
34 โ”‚ newMessage: Result
ยท โ”€โ”€โ”€โ”ฌโ”€โ”€
ยท โ•ฐโ”€โ”€ not found in this scope
35 โ”‚ }
โ•ฐโ”€โ”€โ”€โ”€

apollo-compiler validation error

ร— expected identifier
โ•ญโ”€[1:1]
1 โ”‚ โ•ญโ”€โ–ถ query {
2 โ”‚ โ”‚ cat {
3 โ”‚ โ”‚ name
4 โ”‚ โ”‚ }
5 โ”‚ โ”‚ }
6 โ”‚ โ”œโ”€โ–ถ
ยท โ•ฐโ”€โ”€โ”€โ”€ provide a name for this definition
7 โ”‚ query getPet {
8 โ”‚ cat {
โ•ฐโ”€โ”€โ”€โ”€
help: GraphQL allows a short-hand form for defining query operations when only that one operation exists in the
document. There are 4 operations in this document.

apollo-compiler validation error

ร— the operation `getPet` is defined multiple times in the document
โ•ญโ”€[6:1]
6 โ”‚
7 โ”‚ โ•ญโ”€โ–ถ query getPet {
8 โ”‚ โ”‚ cat {
9 โ”‚ โ”‚ owner {
10 โ”‚ โ”‚ name
11 โ”‚ โ”‚ }
12 โ”‚ โ”‚ }
13 โ”‚ โ”‚ }
14 โ”‚ โ”œโ”€โ–ถ
ยท โ•ฐโ”€โ”€โ”€โ”€ previous definition of `getPet` here
15 โ”‚ โ•ญโ”€โ–ถ query getPet {
16 โ”‚ โ”‚ cat {
17 โ”‚ โ”‚ treat
18 โ”‚ โ”‚ }
19 โ”‚ โ”‚ }
20 โ”‚ โ”œโ”€โ–ถ
ยท โ•ฐโ”€โ”€โ”€โ”€ `getPet` is redefined here
21 โ”‚ subscription sub {
22 โ”‚ newMessage {
โ•ฐโ”€โ”€โ”€โ”€
help: `getPet` must only be defined once in this document.

apollo-compiler validation error

ร— Subscriptions operations can only have one root field
โ•ญโ”€[20:1]
20 โ”‚
21 โ”‚ โ•ญโ”€โ–ถ subscription sub {
22 โ”‚ โ”‚ newMessage {
23 โ”‚ โ”‚ body
24 โ”‚ โ”‚ sender
25 โ”‚ โ”‚ }
26 โ”‚ โ”‚ disallowedSecondRootField
27 โ”‚ โ”‚ }
28 โ”‚ โ”œโ”€โ–ถ
ยท โ•ฐโ”€โ”€โ”€โ”€ subscription with 2 root fields
29 โ”‚ type Query {
30 โ”‚ cat: Pet
โ•ฐโ”€โ”€โ”€โ”€
help: There are 2 root fields: newMessage, disallowedSecondRootField. This is not allowed.

apollo-compiler validation error

ร— Cannot query `disallowedSecondRootField` field
โ•ญโ”€[25:1]
25 โ”‚ }
26 โ”‚ disallowedSecondRootField
ยท โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
ยท โ•ฐโ”€โ”€ `disallowedSecondRootField` field is not in scope
27 โ”‚ }
28 โ”‚
โ•ฐโ”€โ”€โ”€โ”€
help: `disallowedSecondRootField` is not defined on `Subscription` type

โŒ Found 7 errors in 3 ms.
๐Ÿ‘€ Watching ./schemas/cat.graphql for changes
```

If you make a change to the schema on the file system, the CLI will detect the change and print the updated diagnostics to the terminal.

### With `rover graph introspect`, `curl`, and `jq`

```console
$ rover graph introspect https://countries.trevorblades.com | curl -X POST -sSL --data-binary @- https://awc.fly.dev | jq -r .pretty
apollo-compiler validation advice

> Custom scalars should provide a scalar specification URL via the @specifiedBy directive
,-[1:1]
1 | scalar _Any
: ^^^^^^|^^^^^
: `-- consider adding a @specifiedBy directive to this scalar definition
2 | type Country {
3 | code: ID!
`----
```

### In the browser _(under development)_

Visit [awc.fly.dev](https://awc.fly.dev), type GraphQL into the left panel and watch diagnostics appear on the right. Display for this is a bit buggy at the moment but it uses the same POST request to validate GraphQL.