Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io.github.mstachniuk.graphqljavaexample.company.CompanyDataFetcher;
import io.github.mstachniuk.graphqljavaexample.customer.*;
import io.github.mstachniuk.graphqljavaexample.item.ItemDataFetcher;
import io.github.mstachniuk.graphqljavaexample.node.NodeResolver;
import io.github.mstachniuk.graphqljavaexample.order.OrderDataFetcher;
import io.github.mstachniuk.graphqljavaexample.search.SearchDataFetcher;
import io.github.mstachniuk.graphqljavaexample.search.SearchResultResolver;
Expand Down Expand Up @@ -66,6 +67,7 @@ private GraphQLFieldDefinition customerDefinition() {
.name("id")
.type(new GraphQLNonNull(GraphQLString)))
.type(new GraphQLNonNull(GraphQLObjectType.newObject()
.withInterface(nodeInterfaceDefinition())
.name("Customer")
.field(GraphQLFieldDefinition.newFieldDefinition()
.name("id")
Expand Down Expand Up @@ -390,4 +392,15 @@ private GraphQLFieldDefinition searchDefinition() {
.dataFetcher(searchDataFetcher)
.build();
}

private GraphQLInterfaceType nodeInterfaceDefinition() {
return GraphQLInterfaceType.newInterface()
.name("Node")
.field(GraphQLFieldDefinition.newFieldDefinition()
.name("id")
.type(new GraphQLNonNull(GraphQLID))
.build())
.typeResolver(new NodeResolver())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.github.mstachniuk.graphqljavaexample.node;

import graphql.TypeResolutionEnvironment;
import graphql.schema.GraphQLObjectType;
import graphql.schema.TypeResolver;

public class NodeResolver implements TypeResolver {
@Override
public GraphQLObjectType getType(TypeResolutionEnvironment env) {
return null;
}
}
14 changes: 10 additions & 4 deletions src/main/resources/graphql/model.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type Customer {
orders: [Order]
}

type Company {
type Company implements Node {
id: ID!
name: String!
website: String!
Expand All @@ -23,7 +23,7 @@ enum Status {
NEW, CANCELED, DONE
}

type Item {
type Item implements Node {
id: ID!
name: String!
amount: Int
Expand Down Expand Up @@ -87,18 +87,24 @@ interface User {
email: String!
}

type Admin implements User {
type Admin implements Node & User {
id: ID!
name: String!
email: String!
superAdmin: Boolean!
}

type Moderator implements User {
type Moderator implements Node & User {
id: ID!
name: String!
email: String!
permissions: [String]
}

union SearchResult = Customer | Admin | Moderator

#An object with an ID
interface Node {
#The ID of an object
id: ID!
}