Giter VIP home page Giter VIP logo

apollographql / apollo-kotlin Goto Github PK

View Code? Open in Web Editor NEW
3.7K 3.7K 641.0 262.95 MB

:robot:  A strongly-typed, caching GraphQL client for the JVM, Android, and Kotlin multiplatform.

Home Page: https://www.apollographql.com/docs/kotlin

License: MIT License

Kotlin 92.73% Java 6.24% CSS 0.88% JavaScript 0.03% HTML 0.12%
android apollographql graphql graphql-client kotlin kotlin-multiplatform multiplatform

apollo-kotlin's People

Contributors

abernix avatar adammc331 avatar ansman avatar baconz avatar bignimbus avatar bod avatar brianplummer avatar designatednerd avatar digitalbuddha avatar dsteve595 avatar felipecsl avatar ghostbuster91 avatar github-actions[bot] avatar goooler avatar hwillson avatar jaredsburrows avatar jpvajda avatar kassim avatar martinbonnin avatar marwanad avatar meschreiber avatar oliveeyay avatar renovate-bot avatar renovate[bot] avatar sav007 avatar stylianosgakis avatar tasomaniac avatar trevorblades avatar visheshvadhera avatar zacsweers avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

apollo-kotlin's Issues

[Code Generation] Handle Directives on inlineFragments

Example query:

query inlineFragmentNoType($expandedInfo: Boolean) {
  user(handle: "zuck") {
    id
    name
    ... on User @include(if: $expandedInfo) {
      firstName
      lastName
      birthday
    }
  }
}

For fragment spreads, we can augment the fragment spread in the IR with an isConditional field.

Generated classes are created under generatedIR package

The gradle plugin doesn't seem to be respecting the original package name of each graphql file and just adding them all into the generatedIR package (eg.: build/generated/source/apollo/generatedIR/DroidDetails.java)

The generated package name should match the original file path.

Add a schema download task

apollo-codegen supports downloading the schema by sending an introspection query to the server.
It would be nice to have a task that utilizes apollo-codegen download

[Code Generation] Generate query wrapper class around query text source and variables

Create generic GraphQLQuery interface like iOS does
Generate query class implemtentation for each query by implementing GraphQLQuery.
Generated query class implemtentations should allow set arguments.

See https://github.com/apollostack/apollo-android/blob/design-doc/DESIGN.md#query-classes
Swift examples can be found here: https://github.com/apollostack/apollo-ios/blob/master/Tests/ApolloTests/StarWars/API.swift

[Runtime] Mapping json response to generated data models

Query data model generated by apollo android plugin is represented by interfaces. In order to deserialize query response (json) and map it to the data model, apollo service requires to know about the user defined instance classes of that data model. Generated interface declares only accessor api calls to fields (no setters and of course no fields).

Questions:

  1. As we discussed before, custom retrofit converter will be implemented in order to support deserializing response. How this converter will get knowledge about setters / fields of user defined data model implementations to be able to map json response fields?

  2. How converter is going to instantiate the user defined instances of the model interfaces?

One approach that we considered user uses AutoValue lib to generate instances of data model interfaces. Here is an example of generated model interface:

public interface Data extends Query.Data {
     Hero hero();

    interface Hero {
       String name();

       AsHuman asHuman();

      interface AsHuman {
         String name();

         List<Friend> friends();

         Float height();

        interface Friend {
           String name();

           List<Episode> appearsIn();
        }
      }
...

Then from user to use AutoValue requires to define abstract classes / interfaces that extend all interfaces: Data, Data.Hero, Data.Hero.AsHuman, Data.Hero.AsHuman.Friend etc. with @AutoValue annotation that seems too overwhelming . Even more AutoValue generates immutable value objects that initialize fields inside constructor. So retrofit converter has to parse response json and pass parsed field values as parameters to this constructor.
But converter doesn't know anything about user defined instance classes and especially about how to construct them, so it will require some sort of factory the same approach as SQLDelight implements.

All this complication brings to question, maybe we have to change our code generation to have model be classes with fields, rather then interfaces.

@felipecsl @martijnwalraven @marwanad

[Code Generation] Add Retrofit service interface generation support

We can generate Retrofit service with all defined query endpoints to follow with this pattern:

public interface ApiService {
    @POST
    Call<Response<%QUERY_TYPE%.Data>> %QUERY_NAME%(@Body GraphQlOperationRequest<%QUERY_TYPE%.Variables> query);
...
  }

This generated service to be used with Retrofit client:

ApiService apiService = retrofit.create(ApiService.class);

With such service declaration Retrofit client must be configured with base url pointed to graphql endpoint.

 Retrofit retrofit = new Retrofit.Builder()
        .baseUrl("http:// ..... /graphql/")

[Refactoring] Remove code duplication from GraphQLCompilerTest

All Junit tests in GraphQLCompilerTest follow the same pattern:

  1. check actual generated file with expected
  2. compile

A lot of code duplication. We can do better, define only test fixtures (probably map of actual / expected file paths) and run tests against them

[Code Generation] Add support of input types

In order to support mutation operation support input types is required.

Query as example :

mutation CreateReviewForEpisode($ep: Episode!, $review: ReviewInput!) {
  createReview(episode: $ep, review: $review) {
    stars
    commentary
  }
}

IR json:

{
	"operations": [
		{
			"operationName": "CreateReviewForEpisode",
			"operationType": "mutation",
			"variables": [
				{
					"name": "ep",
					"type": "Episode!"
				},
				{
					"name": "review",
					"type": "ReviewInput!"
				}
			],
			"source": "mutation CreateReviewForEpisode($ep: Episode!, $review: ReviewInput!) {\n  createReview(episode: $ep, review: $review) {\n    stars\n    commentary\n  }\n}",
			"fields": [
				{
					"responseName": "createReview",
					"fieldName": "createReview",
					"type": "Review",
					"fields": [
						{
							"responseName": "stars",
							"fieldName": "stars",
							"type": "Int!"
						},
						{
							"responseName": "commentary",
							"fieldName": "commentary",
							"type": "String"
						}
					],
					"fragmentSpreads": [],
					"inlineFragments": []
				}
			],
			"fragmentsReferenced": []
		}
	],
	"fragments": [],
	"typesUsed": [
		{
			"kind": "EnumType",
			"name": "Episode",
			"description": "The episodes in the Star Wars trilogy",
			"values": [
				{
					"name": "NEWHOPE",
					"description": "Star Wars Episode IV: A New Hope, released in 1977."
				},
				{
					"name": "EMPIRE",
					"description": "Star Wars Episode V: The Empire Strikes Back, released in 1980."
				},
				{
					"name": "JEDI",
					"description": "Star Wars Episode VI: Return of the Jedi, released in 1983."
				}
			]
		},
		{
			"kind": "InputObjectType",
			"name": "ReviewInput",
			"description": "The input object sent when someone is creating a new review",
			"fields": [
				{
					"name": "stars",
					"description": "0-5 stars",
					"type": "Int!",
					"defaultValue": null
				},
				{
					"name": "commentary",
					"description": "Comment about the movie, optional",
					"type": "String",
					"defaultValue": null
				},
				{
					"name": "favoriteColor",
					"description": "Favorite color, optional",
					"type": "ColorInput",
					"defaultValue": null
				}
			]
		},
		{
			"kind": "InputObjectType",
			"name": "ColorInput",
			"description": "The input object sent when passing in a color",
			"fields": [
				{
					"name": "red",
					"description": "",
					"type": "Int!",
					"defaultValue": null
				},
				{
					"name": "green",
					"description": "",
					"type": "Int!",
					"defaultValue": null
				},
				{
					"name": "blue",
					"description": "",
					"type": "Int!",
					"defaultValue": null
				}
			]
		}
	]
}

[Runtime] Create simple Apollo object

It should have a simple builder interface that takes at least a retrofit object and is able to fire GraphQL requests using the generated query interfaces and optionally arguments.

[Code Generation] Need details about external types referenced in typesUsed array

From Slack discussion:

felipecsl [12:21 PM]
@martijnwalraven I was looking at the HeroAppearsIn query and the generated IR references the Episode type in the typesUsed array, however its definition can’t be found anywhere in the data. Also I checked the Swift code generated for that query and noticed that it does include a public enum Episode. Sounds like we’re gonna have to add the definition of any external types to the IR so we can generate code based solely on the IR. It sounds like the Swift generator is retrieving that data from somewhere else

[Code Generation] Add support for directives

Add support for @skip and @include directives

query HeroNameInclusionDirective {
     hero {
          name @include(if: someCondition)
        }
}

There would be an isConditional field in the IR and handling those should be somewhat similar to handling nullability.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.