Support for the schema query
aleGuardiola opened this issue · 10 comments
Hi, first of all this is an awesome tool. I think it would be a good idea to add support for the schema query so you can generate the code directly from a graphql endpoint
Ex: dotnet run -- https://localhost:50001/api/graphql -m Date=DateTime
You mean an introspection? I have support for introspection files in my locally cloned project. Will discuss with @lukemurray and check how he sees this and whether he wants this in.
Edit: committed the branch to my fork, see here: https://github.com/cklam2/DotNetGraphQLQueryGen/tree/introspection-support/src
Disclaimer: it's a bit hacky, not feature rich, etc. Created it so it works for my case. Instead of .graphql file, pass a .json file and it will convert the introspection file to C# classes.
There is a second part in your question, namely querying the introspection content from the gql server. That part is not yet available. If you're interested in the introspection query, let me know and I'll post it here.
I’m all for supporting both (annoying gql has both) and would love help with it. My use case doesn’t involved introspection hence I haven’t done it. Please create a pull request and we can collaborate
Yes please post the query you use.
Let me fork the project and start reading the code, I will be happy to create a pull request. By the way, I know this is not related but I am creating a library for graphql in the server that maybe you guys can check it out https://github.com/aleGuardiola/Graphql-Controller I think it is a good idea.
Looking at the code I guess using the compiler that @cklam2 already made I can just get the url from the arguments call the introspection query and passed to the compiler?
Nice, looks like a different approach to what I did here https://github.com/lukemurray/EntityGraphQL
Yes, it is a different approach. I also checked your project before and I really liked, there are some similar projects out there but I wanted something more low level so I can have more freedom
Yep, that is basically it. Pass an introspection query to your server and it'll return a json which you can process with the introspection compiler.
The query that I used, and you can adjust it to your needs:
query IntrospectionQuery {
__schema {
queryType { name }
mutationType { name }
subscriptionType { name }
types {
...FullType
}
directives {
name
description
locations
args {
...InputValue
}
}
}
}
fragment FullType on __Type {
kind
name
description
fields(includeDeprecated: true) {
name
description
args {
...InputValue
}
type {
...TypeRef
}
isDeprecated
deprecationReason
}
inputFields {
...InputValue
}
interfaces {
...TypeRef
}
enumValues(includeDeprecated: true) {
name
description
isDeprecated
deprecationReason
}
possibleTypes {
...TypeRef
}
}
fragment InputValue on __InputValue {
name
description
type { ...TypeRef }
defaultValue
}
fragment TypeRef on __Type {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
}
}
}
}
}
}
}
}
I made a pull request: #16
Merged #16 to fix this. Let me know if there are any specific issues. Thanks all