-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleanup, graphql type registries and a GraphiQL endpoint
- Loading branch information
Showing
17 changed files
with
338 additions
and
107 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package be.florens.craftql.api; | ||
|
||
import be.florens.craftql.CraftQL; | ||
import graphql.kickstart.tools.GraphQLResolver; | ||
import graphql.schema.GraphQLScalarType; | ||
import net.fabricmc.fabric.api.event.registry.FabricRegistryBuilder; | ||
import net.minecraft.util.registry.Registry; | ||
|
||
public class Registries { | ||
|
||
public static final Registry<GraphQLScalarType> SCALARS = FabricRegistryBuilder.createSimple(GraphQLScalarType.class, | ||
CraftQL.id("scalars")).buildAndRegister(); | ||
@SuppressWarnings("unchecked") | ||
public static final Registry<GraphQLResolver<?>> RESOLVERS = FabricRegistryBuilder.createDefaulted( | ||
(Class<GraphQLResolver<?>>) (Class<?>) GraphQLResolver.class, CraftQL.id("resolvers"), | ||
CraftQL.id("root_query")).buildAndRegister(); | ||
// TODO: directives | ||
} |
This file contains 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
This file contains 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
7 changes: 7 additions & 0 deletions
7
src/main/java/be/florens/craftql/resolver/MutationResolver.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package be.florens.craftql.resolver; | ||
|
||
import graphql.kickstart.tools.GraphQLMutationResolver; | ||
|
||
public class MutationResolver implements GraphQLMutationResolver { | ||
|
||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package be.florens.craftql.resolver; | ||
|
||
import be.florens.craftql.CraftQL; | ||
import be.florens.craftql.api.Registries; | ||
import graphql.kickstart.tools.GraphQLResolver; | ||
import net.minecraft.util.registry.Registry; | ||
|
||
public class Resolvers { | ||
|
||
public static final GraphQLResolver<?> ROOT_QUERY = new RootQueryResolver(); | ||
public static final GraphQLResolver<?> MUTATION = new MutationResolver(); | ||
public static final GraphQLResolver<?> SUBSCRIPTION = new SubscriptionResolver(); | ||
public static final GraphQLResolver<?> INVENTORY = new InventoryResolver(); | ||
|
||
public static void registerAll() { | ||
registerResolver("root_query", ROOT_QUERY); | ||
registerResolver("mutation", MUTATION); | ||
registerResolver("subscription", SUBSCRIPTION); | ||
registerResolver("inventory", INVENTORY); | ||
} | ||
|
||
private static void registerResolver(String path, GraphQLResolver<?> resolver) { | ||
Registry.register(Registries.RESOLVERS, CraftQL.id(path), resolver); | ||
} | ||
} |
This file contains 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
30 changes: 30 additions & 0 deletions
30
src/main/java/be/florens/craftql/resolver/SubscriptionResolver.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package be.florens.craftql.resolver; | ||
|
||
import graphql.kickstart.tools.GraphQLSubscriptionResolver; | ||
import net.fabricmc.fabric.api.event.player.PlayerBlockBreakEvents; | ||
import net.minecraft.server.network.ServerPlayerEntity; | ||
import org.reactivestreams.Publisher; | ||
import org.reactivestreams.Subscriber; | ||
|
||
public class SubscriptionResolver implements GraphQLSubscriptionResolver { | ||
|
||
public Publisher<ServerPlayerEntity> onBreakBlock() { | ||
//noinspection ReactiveStreamsPublisherImplementation | ||
return new Publisher<ServerPlayerEntity>() { | ||
private int count; | ||
|
||
@Override | ||
public void subscribe(Subscriber s) { | ||
PlayerBlockBreakEvents.AFTER.register((world, player, pos, state, blockEntity) -> { | ||
count++; | ||
if (count == 10) { | ||
s.onComplete(); | ||
} else { | ||
//noinspection unchecked | ||
s.onNext(player); | ||
} | ||
}); | ||
} | ||
}; | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,19 @@ | ||
package be.florens.craftql.scalar; | ||
|
||
import be.florens.craftql.CraftQL; | ||
import be.florens.craftql.api.Registries; | ||
import graphql.schema.GraphQLScalarType; | ||
import net.minecraft.util.registry.Registry; | ||
|
||
public class Scalars { | ||
|
||
public static final GraphQLScalarType TEXT = GraphQLScalarType.newScalar().name("Text") | ||
.coercing(new TextCoercing()).build(); | ||
public static final GraphQLScalarType TEXT = GraphQLScalarType.newScalar().name("Text").coercing(new TextCoercing()).build(); | ||
|
||
public static void registerAll() { | ||
registerScalar("text", TEXT); | ||
} | ||
|
||
private static void registerScalar(String path, GraphQLScalarType scalar) { | ||
Registry.register(Registries.SCALARS, CraftQL.id(path), scalar); | ||
} | ||
} |
Oops, something went wrong.