-
-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Code generation question #85
Comments
Thanks @benmccann The codegen generates code for queries. A schema is required to resolve the typings. So without any queries there won't be any code generated 😊 |
I do have queries defined in my schema. Or do you mean something else like I need to write queries in my code first? |
A schema doesn't contain queries. A query is something the client sends to the server (which defines the schema) in order to receive a piece of data or trigger some action. A query looks like this: query GraphQLProject {
project(name: "GraphQL") {
tagline
}
} edit: To put it simply: The server defines the schema, the client defines the queries against the schema. This plugin can help you bridge the gap between the two (for example by generating code or by validating that the query can be answered by the schema). |
Ah. I was thinking queries were specified in the schema like this: https://graphql.org/learn/schema/#the-query-and-mutation-types But I might have the terminology wrong. I'm just getting started with GraphQL. I was assuming |
Ah yes, I can see how the naming is a bit confusing. Let me rephrase it a bit: The On the client-side you write a string which describes what you want and this is what you send to the server ( As you correctly derived, the If you want to create an API, then you don't need this plugin at all, you just use All in all, it sounds more complicated then it really is. On the server you define your val schema = Schema(
queries = List(
Field("foo", StringType, resolve = _ => "foo!")
),
mutations = List.empty
) From the client you send a query which requests the field: query MyQuery {
foo
} And you get back something like: {
"data": {
"foo": "foo!"
},
"errors": []
} Hope this clears things up a bit :) |
Closes muuki88#85 Let me know if you think there's a better way to clarify this. Figuring out that it was meant for client-side is where a lot of the initial disconnect was for me
Hi @muuki88, thanks for providing this!
I had a question about getting started. In my
build.sbt
I addedenablePlugins(GraphQLCodegenPlugin)
and nothing else related to the plugin because I have a filesrc/main/resources/schema.graphql
, which I believe is the default value. I ransbt graphqlCodegenSchema
, but nothing happened. I didn't understand if anything else was required. Am I missing something?The text was updated successfully, but these errors were encountered: