Code Monkey home page Code Monkey logo

graphicl's Introduction

Graphicl

Example

Fields

query {
  hero {
    name
    appearsIn
  }
}
GraphQL.query()
  .field("hero")
      .field("name")
      .end()
      .field("appearsIn")
      .end()
  .end()
  .build();
class Hero {
  @GraphQLField
  String name;
  @GraphQLField
  String appearsIn;
}

@GraphQLQuery
class Query {
  @GraphQLField
  Hero hero;
}
query {
  hero {
    name
    friends {
      name
    }
  }
}
GraphQL.query()
  .field("hero")
      .field("name")
      .end()
      .field("friends")
          .field("name")
          .end()
      .end()
  .end()
  .build();
class Friend {
  @GraphQLField
  String name;
}

class Hero {
  @GraphQLField
  String name;
  @GraphQLField
  List<Firend> friends;
}

@GraphQLQuery
class Query {
  @GraphQLField
  Hero hero;
}

Arguments

query {
  human(id: "1000") {
    name
    height
  }
}
GraphQL.query()
  .field("human").arg("id", "1000")
      .field("name")
      .end()
      .field("height")
      .end()
  .end()
  .build();
class Human {
  @GraphQLField
  String name;
  @GraphQLField
  Integer height;
}

@GraphQLQuery
class Query {
  @GraphQLField(args = { @GraphQLArg(name = "id", value = "1000") })
  Human human;
}
query {
  human(id: "1000") {
    name
    height(unit: FOOT)
  }
}
enum Unit {
    FOOT
}

GraphQL.query()
  .field("human").arg("id", "1000")
      .field("name")
      .end()
      .field("height").arg("unit", Unit.FOOT)
      .end()
  .end()
  .build();
class Human {
  @GraphQLField
  String name;
  @GraphQLField(args = { @GraphQLArg(name = "unit", value = Unit.FOOT) })
  Integer height;
}

@GraphQLQuery
class Query {
  @GraphQLField(args = { @GraphQLArg(name = "id", value = "1000") })
  Human human;
}

Aliases

query {
  empireHero: hero(episode: EMPIRE) {
    name
  }
  jediHero: hero(episode: JEDI) {
    name
  }
}
enum Episode {
    EMPIRE, JEDI
}

GraphQL.query()
  .field("hero").alias("empireHero").arg("episode", Episode.EMPIRE)
      .field("name")
      .end()
  .end()
  .field("hero").alias("jediHero").arg("episode", Episode.JEDI)
      .field("name")
      .end()
  .end()
  .build();            
class Hero {
  @GraphQLField
  String name;
}

@GraphQLQuery
class Query {
  @GraphQLField(name = "hero", args = { @GraphQLArg(name = "episode", value = Episode.EMPIRE) })
  Hero empireHero;

  @GraphQLField(name = "hero", args = { @GraphQLArg(name = "episode", value = Episode.JEDI) })  
  Hero jediHero;
}

Fragments

query {
  leftComparison: hero(episode: EMPIRE) {
    ...comparisonFields
  }
  rightComparison: hero(episode: JEDI) {
    ...comparisonFields
  }
}

fragment comparisonFields on Character {
  name
  appearsIn
  friends {
    name
  }
}
enum Episode {
    EMPIRE, JEDI
}

GraphQL.query()
  .field("hero").alias("leftComparison").arg("episode", Episode.EMPIRE)
      .fragmentSpread("comparisonFields")
      .end()
  .end()
  .field("hero").alias("rightComparison").arg("episode", Episode.JEDI)
      .fragmentSpread("comparisonFields")
      .end()
  .end()
  .build();

GraphQL.fragmentDefinition("comparisonFields").on("Character")
  .field("name")
  .end()
  .field("appearsIn")
  .end()
  .field("friends")
      .field("name")
      .end()
  .end()
  .build();

Not support yet ...

class Friend {
  @GraphQLField
  String name;
}

class Hero {
  @GraphQLField
  String name;
  @GraphQLField
  String appearsIn;
  @GraphQLField
  List<Friend> friends;
}

@GraphQLQuery
class Query {
  @GraphQLField(name = "hero", args = { @GraphQLArg(name = "episode", value = Episode.EMPIRE) })
  Hero leftComparison;

  @GraphQLField(name = "hero", args = { @GraphQLArg(name = "episode", value = Episode.JEDI) })  
  Hero rightComparison;
}
query {
  leftComparison: hero(episode: EMPIRE) {
    name
    appearsIn
    friends {
      name
    }
  }
  rightComparison: hero(episode: JEDI) {
    name
    appearsIn
    friends {
      name
    }
  }
}

Operation name

query HeroNameAndFriends {
  hero {
    name
    friends {
      name
    }
  }
}
GraphQL.query("HeroNameAndFriends")
  .field("hero")
      .field("name")
      .end()
      .field("friends")
          .field("name")
          .end()
      .end()
  .end()
  .build());                          
class Friend {
  @GraphQLField
  String name;
}

class Hero {
  @GraphQLField
  String name;
  @GraphQLField
  List<Firend> friends;
}

@GraphQLQuery("HeroNameAndFriends")
class Query {
  @GraphQLField
  Hero hero;
}

Variables

query HeroNameAndFriends($episode: Episode) {
  hero(episode: $episode) {
    name
    friends {
      name
    }
  }
}

{
  "episode": "JEDI"
}
GraphQL.query("HeroNameAndFriends")
  .var(GraphQL.var("episode")).type("Episode")
  .end()
  .field("hero").arg("episode", GraphQL.var("episode"))
      .field("name")
      .end()
      .field("friends")
          .field("name")
          .end()
      .end()
  .end()
  .build());                            
class Friend {
  @GraphQLField
  String name;
}

class Hero {
  @GraphQLField
  String name;
  @GraphQLField
  List<Firend> friends;
}

@GraphQLQuery(name = "HeroNameAndFriends",
              vars = { @GraphQLVar(var = GraphQL.var("episode"), type = "Episode") })
class Query {
  @GraphQLField(args = { @GraphQLArg(name = "episode", value = GraphQL.var("episode")) })
  Hero hero;
}

Default variables

query HeroNameAndFriends($episode: Episode = JEDI) {
  hero(episode: $episode) {
    name
    friends {
      name
    }
  }
}
GraphQL.query("HeroNameAndFriends")
  .var(GraphQL.var("episode")).type("Episode").defaultValue(Episode.JEDI)
  .end()
  .field("hero").arg("episode", GraphQL.var("episode"))
      .field("name")
      .end()
      .field("friends")
          .field("name")
          .end()
      .end()
  .end()
  .build());                            
class Friend {
  @GraphQLField
  String name;
}

class Hero {
  @GraphQLField
  String name;
  @GraphQLField
  List<Firend> friends;
}

@GraphQLQuery(name = "HeroNameAndFriends",
              vars = { @GraphQLVar(var = GraphQL.var("episode"), type = "Episode", defaultValue = Episode.JEDI) })
class Query {
  @GraphQLField(args = { @GraphQLArg(name = "episode", value = GraphQL.var("episode")) })
  Hero hero;
}

Directives

query Hero($episode: Episode, $withFriends: Boolean!) {
  hero(episode: $episode) {
    name
    friends @include(if: $withFriends) {
      name
    }
  }
}
GraphQL.query("Hero")
  .var(GraphQL.var("episode")).type("Episode")
  .end()
  .var(GraphQL.var("withFriends")).type("Boolean!")
  .end()
  .field("hero").arg("episode", GraphQL.var("episode"))
      .field("name")
      .end()
      .field("friends").include(GraphQL.var("withFriends"))
          .field("name")
          .end()
      .end()
  .end()
  .build());                           
class Friend {
  @GraphQLField
  String name;
}

class Hero {
  @GraphQLField
  String name;
  @GraphQLField(include = GraphQL.var("withFriends"))
  List<Friend> friends;
}

@GraphQLQuery(name = "Hero",
              vars = {@GraphQLVar(var = GraphQL.var("episode"), type = "Episode"),
                      @GraphQLVar(var = GraphQL.var("withFriends"), type = "Boolean!")})
class Query {
  @GraphQLField(args = { @GraphQLArg(name = "episode", value = GraphQL.var("episode")) })
  Hero hero;
}

Mutations

mutation CreateReviewForEpisode($ep: Episode!, $review: ReviewInput!) {
  createReview(episode: $ep, review: $review) {
    stars
    commentary
  }
}
GraphQL.mutation("CreateReviewForEpisode")
  .var(GraphQL.var("ep")).type("Episode!")
  .end()
  .var(GraphQL.var("review")).type("ReviewInput!")
  .end()
  .field("createReview").arg("episode", GraphQL.var("ep")).arg("review", GraphQL.var("review"))
      .field("stars")
      .end()
      .field("commentary")
      .end()
  .end()
  .build());      
class CreateReview {
  @GraphQLField
  Integer stars;
  @GraphQLField
  String commentary;
}

@GraphQLMutation(name = "CreateReviewForEpisode",
                 vars = {@GraphQLVar(var = GraphQL.var("ep"), type = "Episode!"),
                         @GraphQLVar(var = GraphQL.var("review"), type = "ReviewInput!")})
class Mutation {
  @GraphQLField(args = { @GraphQLArg(name = "episode", value = GraphQL.var("ep")),
                         @GraphQLArg(name = "review", value = GraphQL.var("review"))})
  CreateReview createReview;
}

Inline Fragments

query HeroForEpisode($ep: Episode!) {
  hero(episode: $ep) {
    name
    ... on Droid {
      primaryFunction
    }
    ... on Human {
      height
    }
  }
}
GraphQL.query("HeroForEpisode")
    .var(GraphQL.var("ep")).type("Episode!")
    .end()
    .field().name("hero").arg("episode", GraphQL.var("ep"))
        .field("name")
        .end()
        .inlineFragment().on("Droid")
            .field("primaryFunction")
            .end()
        .end()
        .inlineFragment().on("Human")
            .field("height")
            .end()
        .end()
    .end()
    .build());
class Hero {
  @GraphQLField
  String name;
  @GraphQLInlineFragment(on = "Droid")
  String primaryFunction;
  @GraphQLInlineFragment(on = "Human")
  Integer height;
}

@GraphQLQuery(name = "HeroForEpisode",
              vars = {@GraphQLVar(var = GraphQL.var("ep"), type = "Episode!")})
class Query {
  @GraphQLField(@GraphQLArg(name = "episode", value = GraphQL.var("ep")))
  Hero hero;
}

graphicl's People

Contributors

eunmin avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.