Last active
June 12, 2019 17:31
-
-
Save DarkSeraphim/f3b804d411f650cdf679e7f956598e5a to your computer and use it in GitHub Desktop.
GraphQL design
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
query GetUser { | |
user { | |
name | |
} | |
} | |
type Query { | |
user(id: ID!): User | |
} | |
type User { | |
id: ID! | |
name: String | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Query { | |
private User.Query user; | |
private Query(Builder builder) { | |
user = builder.user; | |
} | |
public static Builder builder() { | |
return new Builder(); | |
} | |
public static class Builder { | |
private User.Query user; | |
public Builder user(ID id) { | |
this.user = new User.Query(id); | |
return this; | |
} | |
public Query build() { | |
return new Query(this); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class User { | |
private final ID id; | |
private final String name; | |
private User(Builder builder) { | |
this.id = builder.id; | |
this.name = builder.name; | |
} | |
public ID getId() { | |
return this.id; | |
} | |
public Optional<String> getName() { | |
return Optional.ofNullable(this.name); | |
} | |
public static Builder builder(ID id) { | |
return new Builder(id); | |
} | |
public static class Builder { | |
private final ID id; | |
private String name; | |
public Builder(ID id) { | |
this.id = id | |
} | |
public Builder name(String name) { | |
this.name = name; | |
return this; | |
} | |
public User build() { | |
return new User(this); | |
} | |
} | |
static class Query { | |
private final ID id; | |
Query(ID id) { | |
Preconditions.notNull(id, "id is a required field"); | |
this.id = id; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment