What is the difference between makeExecutableSchema & buildClientSchema in Apollo GraphQL - react-apollo

I'm trying to build a mocking infrastructure for our react client. Getting confused between the two.

buildClientSchema vs makeExecutableSchema
makeExecutableSchema can be used to mock schema types, resolvers, logger, etc...
buildClientSchema can only be used to mock the schema types, but cannot be used to execute queries/mutations.
If you want to mock and test the return (query) data use makeExecutableSchema if is just to test the schema type definitions use buildClientSchema.
It always comes into what you need to test.

Related

Apollo graphQL subscription Which package to use

I see for Apollo graphql if i wan to use plain Apollo subscription, I can import PubSub from Apollo-server or graphql-subscription . Wondering which one is correct to use ?
Take look at the dependencies of apollo-server.
graphql-subscriptions is the dependency of apollo-server.
apollo-server just re-exports all modules from graphql-subscriptions without modifying anything.
So, you can import PubSub from any package. They are the same.

How to use `autoSchemaFile` only for one resolver in nestjs

It is possible allow auto schema file generation (autoSchemaFile) in nestjs only for one resolver?
I would like to have one autogenerated scheme and rest of is written manually.
Thank you.

How to generate Kotlin and or Java data model from GraphQL schema

My current project has switched to GraphQL API's and I wish to automate the generation of model objects that match both Query/Mutations requests/responses.
All I require is the model classes, I do not want to use tools such as Apollo at runtime in my Application.
I require model classes to be either Java or Kotlin.
I found this https://www.graphql-java-kickstart.com/tools/schema-definition/
however this appears to require me to create the model classes my self...
based on this statement "GraphQL Java Tools will expect to be given three classes that map to the GraphQL types: Query, Book, and Author. The Data classes for Book and Author are simple:"
What am I missing?
When I attempt use Apollo-cli to download my schema I get this error
~ - $ npx apollo-cli download-schema $https://my.graphql.end.point/graphql --output schema.json
Error while fetching introspection query result: only absolute urls are supported
Surely this is an basic requirement when employing GraphQL
So if I understand you correctly what you are trying to do is to a) download and locally create the schema from an existing graphql endpoint and b) create java model objects from this schema.
To download the schema you can use the graphql-cli. First install via npm install -g graphql-cli and run graphql init to setup your .graphqlconfig. Finally run graphql get-schema to download the schema from the defined endpoint.
Next you want to leverage a Java code generator that takes the GraphQL schema and creates:
Interfaces for GraphQL queries, mutations and subscriptions
Interfaces for GraphQL unions
POJO classes for GraphQL types
Enum classes for each GraphQL enum
There are various options depending on your setup / preferences (e.g. gradle vs maven):
https://graphql-maven-plugin-project.graphql-java-generator.com/index.html
https://github.com/kobylynskyi/graphql-java-codegen-gradle-plugin
https://github.com/kobylynskyi/graphql-java-codegen-maven-plugin
I recommend you to check out the first option, since it looks very well documented and also provides full flexibility after generating the desired helpers:
graphql-java-generator generates the boilerplate code, and lets you
concentrate on what’s specific to your use case. Then, the running
code doesn’t depend on any dependencies from graphql-java-generator.
So you can get rid of graphql-java-generator at any time: just put the
generated code in your SCM, and that’s it.
When in client mode, you can query the server with just one line of
code.
For instance :
Human human = queryType.human("{id name appearsIn homePlanet
friends{name}}", "180");
In this mode, the plugin generates:
One java class for the Query object, One java class for the Mutation
object (if any), One POJO for each standard object of the GraphQL
object, All the necessary runtime is actually attached as source code
into your project: the generated code is stand-alone. So, your
project, when it runs, doesn’t depend on any external dependency from
graphql-java-generator.

Does it make sense to use DataLoader without a db?

I found out about DataLoader package reading GraphQL tutorial but all of the examples for DataLoader package corresponds to some databases.
Does it make sense to use DataLoader if my GraphQL layer is just a layer on top of the REST API?

mock api response in graphql-java

I have a graphql API written using graphql-java-tools and graphql-java. I want to mock a query operation. How can I do this? Is Apollo graphql-tools the only way to achieve this. I havent used any other apolo library in my project yet and didnt want to go that route for just mocking service.
There is no library that supports mocking in java as of now( Apollo-graphql-tools supports only nodejs). I think best way is to mock it yourself creating new objects.

Resources