Skip to content

#381 - Adds the ability to compile and build executable schemas - #386

Merged
bbakerman merged 3 commits into
graphql-java:masterfrom
bbakerman:381-graphql-schema-idl-support
Apr 30, 2017
Merged

bbakerman merged 3 commits into
graphql-java:masterfrom
bbakerman:381-graphql-schema-idl-support

Conversation

@bbakerman

Copy link
Copy Markdown
Member

Adds the ability to compile and build executable schema from schema IDL definitions

@dh94

dh94 commented Apr 20, 2017

Copy link
Copy Markdown
Contributor

looks really cool - awesome work!
inspiration came from graphql-tools right?
i think this will be a huge step up for this repository!

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 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think maybe the name RuntimeWiring could be a bit misleading, why not call it ResolversMap like in graphql-tools?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will be ok but let me add a test to ensure its ok to do

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@jplock

jplock commented Apr 22, 2017

Copy link
Copy Markdown

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)?

@apottere

apottere commented Apr 24, 2017 •

Copy link
Copy Markdown
Contributor

@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.

@apottere

Copy link
Copy Markdown
Contributor

That being said, @dh94 you might be interested in https://github.com/graphql-java/graphql-java-tools

@dh94

dh94 commented Apr 24, 2017

Copy link
Copy Markdown
Contributor

@apottere i saw that repo, but this seems more clean

@ieugen

ieugen commented Apr 25, 2017

Copy link
Copy Markdown

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.

[1] https://github.com/Distelli/graphql-apigen

@andimarek andimarek added this to the 3.0.0 milestone Apr 26, 2017

@andimarek andimarek left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}


public static class TypeRuntimeWiring {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest extracting the class into in its own file.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Map<Class, TypePrinter<?>> printers = new LinkedHashMap<>();


{

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

private final Map<String, DataFetcher> fieldDataFetchers = new LinkedHashMap<>();
private TypeResolver typeResolver;

public Builder() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the constructor does nothing, It would not add one, imho.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants