Skip to content

Commit

Permalink
Support query to get a printer by name
Browse files Browse the repository at this point in the history
  • Loading branch information
khelwood committed Jun 21, 2023
1 parent 989bb9a commit 1079ca0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/main/java/uk/ac/sanger/sprint/GraphQLDataFetchers.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ public DataFetcher<Collection<Printer>> getPrinters() {
};
}

public DataFetcher<Printer> getPrinter() {
return dfe -> {
String hostname = dfe.getArgument("hostname");
return config.getPrinters().get(hostname);
};
}

private Printer getPrinter(String hostname) {
Printer printer = config.getPrinters().get(hostname);
if (printer==null) {
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/uk/ac/sanger/sprint/GraphQLProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
import com.google.common.io.Resources;
import graphql.GraphQL;
import graphql.schema.GraphQLSchema;
import graphql.schema.idl.RuntimeWiring;
import graphql.schema.idl.SchemaGenerator;
import graphql.schema.idl.SchemaParser;
import graphql.schema.idl.TypeDefinitionRegistry;
import graphql.schema.idl.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -55,6 +52,7 @@ private RuntimeWiring buildWiring() {
return RuntimeWiring.newRuntimeWiring()
.type(newTypeWiring("Query")
.dataFetcher("printers", graphQLDataFetchers.getPrinters())
.dataFetcher("printer", graphQLDataFetchers.getPrinter())
.dataFetcher("printerTypes", graphQLDataFetchers.getPrinterTypes())
.dataFetcher("printStatus", graphQLDataFetchers.getPrintStatus())
.dataFetcher("labelTypes", graphQLDataFetchers.getLabelTypes()))
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ enum Rotation {
type Query {
# Get the list of printers, optionally filtered by label type
printers(labelType: String): [Printer!]!
# Get the named printer, if it exists
printer(hostname: String!): Printer
# Get the list of printer types
printerTypes: [PrinterType!]!
# Get the status of a print job
Expand Down

0 comments on commit 1079ca0

Please sign in to comment.