Repository navigation
#381 - Adds the ability to compile and build executable schemas - #386
Conversation
…chemas from schema IDL definitions
|
looks really cool - awesome work! great job!! |
| * A runtime wiring is a specification of data fetchers, type resolves and custom scalars that are needed | ||
| * to wire together a functional {@link GraphQLSchema} | ||
| */ | ||
| public class RuntimeWiring { |
There was a problem hiding this comment.
I think maybe the name RuntimeWiring could be a bit misleading, why not call it ResolversMap like in graphql-tools?
There was a problem hiding this comment.
I thought about calling it "Resolvers" but decided against it because DataFetchers are not known as Resolvers and hence it doesnt ring true for graphql-java
There was a problem hiding this comment.
We could rename DataFetcher to Resolver.
| List<GraphQLError> errors = new ArrayList<>(); | ||
|
|
||
| Map<String, TypeDefinition> tempTypes = new LinkedHashMap<>(); | ||
| typeRegistry.types.values().forEach(newEntry -> define(this.types, tempTypes, newEntry).ifPresent(errors::add)); |
There was a problem hiding this comment.
I see that you add an error if the type already exists in the current registry,
so if I'm not mistaken when circular dependencies are introduced an error will be thrown here.
maybe we can take the same approach as in graphql-tools to avoid it? http://dev.apollodata.com/tools/graphql-tools/generate-schema.html#modularizing
There was a problem hiding this comment.
I think this will be ok but let me add a test to ensure its ok to do
There was a problem hiding this comment.
OK added and extra test to confirm. Circular dependencies are ok and handled ok.
eg
type Author {
post : [Post]
}
and in another file
type Post {
author : Author;
}
The code only cares at this stage for top level types
References to types are resolved later in the SchemaGenerator
…ure to throw SchemaProblem
|
Just curious, but how does this related to https://github.com/graphql-java/graphql-java-tools or are they both doing basically the same thing (schema file -> GraphQLSchema)? |
|
@jplock they are really similar, but graphql-java-tools goes one step further and dynamically creates your data fetchers for you and infers type/field names. As it stands, this is still a much less opinionated approach. I still have to look at it a little more, but it's possible I can wrap this in graphql-java-tools so there's less duplicated logic. |
|
That being said, @dh94 you might be interested in https://github.com/graphql-java/graphql-java-tools |
|
@apottere i saw that repo, but this seems more clean |
|
Can't wait for this to get merged. Any idea on when it is going to happen? I am really interested iusing graphql with schema generation. So far, there is graphql-apigen but I believe having this functionality in the core project (or community) makes more sense. How can we help out? Let me know and I might find some time to work on this project. |
andimarek
left a comment
There was a problem hiding this comment.
Overall great work. :-)
Just had some minor things that would be nice to change.
We should add some more tests though, but we can do that after it is merged and I am happy to help with that
| import java.util.Collections; | ||
| import java.util.List; | ||
|
|
||
| class BaseError extends RuntimeException implements GraphQLError { |
There was a problem hiding this comment.
I think all of our Exceptions should derive from GraphQLException
I know we are not consistent on this currently, but nevertheless I wanted to mention it.
| } | ||
|
|
||
|
|
||
| public static class TypeRuntimeWiring { |
There was a problem hiding this comment.
I would suggest extracting the class into in its own file.
| Map<Class, TypePrinter<?>> printers = new LinkedHashMap<>(); | ||
|
|
||
|
|
||
| { |
There was a problem hiding this comment.
I think it is a bad practise to use instance initializers. I also think printers should be declared in the upper part of the class together with the others variables.
| private final Map<String, DataFetcher> fieldDataFetchers = new LinkedHashMap<>(); | ||
| private TypeResolver typeResolver; | ||
|
|
||
| public Builder() { |
There was a problem hiding this comment.
If the constructor does nothing, It would not add one, imho.
Adds the ability to compile and build executable schema from schema IDL definitions