JraphQL antlr parser

GraphQL with Java

License

License

Categories

Categories

Ant Build Tools ANTLR Compiler-compiler
GroupId

GroupId

me.wener.jraphql
ArtifactId

ArtifactId

jraphql-parser-antlr
Last Version

Last Version

0.0.9
Release Date

Release Date

Type

Type

jar
Description

Description

JraphQL antlr parser
GraphQL with Java

Download jraphql-parser-antlr

How to add to project

<!-- https://jarcasting.com/artifacts/me.wener.jraphql/jraphql-parser-antlr/ -->
<dependency>
    <groupId>me.wener.jraphql</groupId>
    <artifactId>jraphql-parser-antlr</artifactId>
    <version>0.0.9</version>
</dependency>
// https://jarcasting.com/artifacts/me.wener.jraphql/jraphql-parser-antlr/
implementation 'me.wener.jraphql:jraphql-parser-antlr:0.0.9'
// https://jarcasting.com/artifacts/me.wener.jraphql/jraphql-parser-antlr/
implementation ("me.wener.jraphql:jraphql-parser-antlr:0.0.9")
'me.wener.jraphql:jraphql-parser-antlr:jar:0.0.9'
<dependency org="me.wener.jraphql" name="jraphql-parser-antlr" rev="0.0.9">
  <artifact name="jraphql-parser-antlr" type="jar" />
</dependency>
@Grapes(
@Grab(group='me.wener.jraphql', module='jraphql-parser-antlr', version='0.0.9')
)
libraryDependencies += "me.wener.jraphql" % "jraphql-parser-antlr" % "0.0.9"
[me.wener.jraphql/jraphql-parser-antlr "0.0.9"]

Dependencies

compile (5)

Group / Artifact Type Version
me.wener.jraphql : jraphql-lang jar 0.0.9
com.fasterxml.jackson.core : jackson-databind jar 2.9.4
org.antlr : antlr4-runtime jar 4.7.1
org.projectlombok : lombok Optional jar 1.16.20
org.slf4j : slf4j-api jar 1.7.25

test (2)

Group / Artifact Type Version
org.slf4j : slf4j-simple jar 1.7.24
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

JraphQL

Java with GraphQL

Module Description
jraphql-lang GraphQL language representation
jraphql-runtime GraphQL execution engine
jraphql-parser-antlr Parser written in Antlr4 parse to jraphql-lang

Get Started

<dependency>
  <groupId>me.wener.jraphql</groupId>
  <artifactId>jraphql-runtimer</artifactId>
  <version>0.0.6</version>
</dependency>
<dependency>
  <groupId>me.wener.jraphql</groupId>
  <artifactId>jraphql-parser-antlr</artifactId>
  <version>0.0.6</version>
</dependency>

Features

Language representation

Feature Description
Serializable can parse or stringify to or from JSON
Immutable friendly to cache or precompile
Buildable every type has a builder for it generated by lombok.
Pluggable language representation is not related to parser impl

Syntax Extension

Add extend by name syntax for object and interface

Weave multi schemas

# common.graphqls
scalar Version

# crm.graphqls
type CrmQuery {
  customer(id:ID!):Customer
  crmVersion: Version!
}
type CrmUser {
  customers: [Customer]
}
extend type Query by CrmQuery
extend type User by CrmUser

# erp.graphqls
type ErpQuery {
  product(id:ID!):Product
}
extend type Query by ErpQuery

Conditional schema

# Only admin can see and use these methods
type AdminMutation {
  changePassword(id:ID,password:String): ChangePasswordPayload
}
extend type Mutation by AdminMutation @Role(role:"admin")

Allowed directives on directive definition, add DIRECTIVE location

directive @JavaType(type:String) on DIRECTIVE
directive @Auth(value:String) @JavaType(type:"Auth") on FIELD_DEFINITION;

Allowed schema has optional name

schema Test {
  query: MyQuery
}

Runtime Extension

  1. Type implements interface don't need to write the fields again.
interface Node {
    id: ID!
}

type User implements Node {
    # id: ID! # This is optional
}
  1. Can disable introspection
    • new MetaResolver().setDisableIntrospection(true)

Embeddable Schema

JraphQL Runtime contain a embedded schema MetaSchema, generated by EmbededSchema.

  • Parse Schema
  • Serialize to JSON
  • Best compress GZip
  • Encode use mime base64
  • Original JSON 32631 byte -> Encoded Base64 5352 byte

Example

StarWar

Queries you can try

mutation addRev {
  createReview(episode: EMPIRE, review: {stars: 4, commentary: "Ok Good"}) {
    stars
    commentary
  }
}

query rev($e:Episode = EMPIRE) {
  hero(episode: $e) {
    id
    name
    appearsIn
  }
  reviews(episode: $e) {
    stars
    commentary
  }
}

query search {
  search(text: "o") {
    __typename
    ... on Human {
      id
      name
    }
    ... on Droid {
      primaryFunction
    }
    ... on Starship {
      length
    }
  }
}

query baseQuery {
  starship(id: "3000") {
    id
    name
    length(unit: FOOT)
  }
  character(id: "2000") {
    id
    ... on Human {
      mass
      starships {
        name
      }
    }
    ... on Droid {
      name
      appearsIn
    }
  }
  human(id: "1003") {
    friendsConnection(after: "1002") {
      friends {
        name
      }
      pageInfo {
        hasNextPage
        startCursor
        endCursor
      }
    }
    friends {
      name
    }
  }
}

Work with GoaphQL

GoaphQL can generate code from schema that depends on jrapgql-api, can directly run on jraphql-graphql-java-adapter.

The generated code is static type and full featured, everything is an interface.

Versions

Version
0.0.9
0.0.8
0.0.7
0.0.6
0.0.5
0.0.4
0.0.3
0.0.2
0.0.1