Replies: 5 comments 19 replies
-
I like the suggestion of SDL being published to a well known endpoint, similar to OIDC jwks. It's extremely common for context to be compiled away from SDL to the deployed schema where developer intention is lost. Custom directives are a great example of this where they may not be stored with your API metadata. |
Beta Was this translation helpful? Give feedback.
-
Agreed on the confusion! As a tooling maintainer it’s very unclear. Stating that introspection & SDL should be equivalent is something I can agree on. It’s very important that each spec feature be reflected in both places as the language evolves, so it’s a good idea to make IDL parity explicit. One thing to note as well - graphql services are not necessarily for server only - as a service description language, you can use it to describe a graphql schema that, for example, is executed entirely in the browser main process, or on a device client (this is how MS Teams 1 worked!). All the more reason why an SDL file may be even more practical than shipping a JSON introspection file. Many services may not want to publish an SDL file to a public and/or well known endpoint as it may be a security concern. I would not reccomend making schema introspection or SDL available in production for most commercial, multitenant platforms. That said, a well known schema endpoint would be nice for those who publish introspection, such as platforms with customer facing APIS, or for internal developer tooling, and has been recommended before. For example, graphql playground, if your initial schema URL returns a failure response, tries /graphql before giving up. I have seen |
Beta Was this translation helpful? Give feedback.
-
It is currently the case that given a spec-compliant GraphQL API, it is possible to generate SDL from the results of introspection that fully represents the GraphQL API, such that you can build a new GraphQL API from only this SDL which would produce the same introspection results. This is a very useful property for tooling because it means that using the SDL generated in this way is equivalent to issuing their own introspection query. However, introspection is still the primary method you should use to see which features of a GraphQL API you can use for various reasons that we've discussed in other threads. The confusion comes when you think of directives applied to the schema as something intrinsic to the schema, simply because they're expressed in SDL. They are not something intrinsic; they're directives - commands - that tell the server to do something special when it's building the schema from SDL. For example, you might have a type Person { ... }
type Query {
allPeople: [Person] @connection
} would become: type Person { ... }
type Query {
allPeople: PersonConnection
}
type PersonConnection {
edges: [PersonEdge]
pageInfo: PageInfo
}
type PersonEdge {
node: Person
cursor: String
} Note how the directive This is what schema directives are in GraphQL today. If you use the reference implementation of GraphQL then (AST nodes aside) there is no runtime details of the directives that were applied - they literally do not exist at runtime, and thus they are not represented in introspection (hard to represent something that does not exist...) and the SDL generated from that introspection does not reflect these directives, again, because they do not exist at runtime. |
Beta Was this translation helpful? Give feedback.
-
GraphQL has one language; for example the following is a valid GraphQL document: type Query {
a: Int
}
query Q {
a
} Note how this is a mixture of schema definition and operation definition using the same language. |
Beta Was this translation helpful? Give feedback.
-
@leebyron @benjie @IvanGoncharov @BoD @twof @michaelstaib @sachee @fotoetienne @yaacovCR @joeynenni |
Beta Was this translation helpful? Give feedback.
-
Overview of IDLs in general
Interface Definition/Description Languages are widely used for describing APIs. There are commonly shared expectations about an IDL and their use. Since IDL is Interface Description Language, the IDL file is expected to completely describe the interface. Meaning, an IDL file is all parties need to know to communicate with each other.
Example: .proto file in gRPC is used to generate, models, client and server stubs in a language of choice. IDL file is a 'source of truth' for an API
The other important point - IDL file is public, all its info is for sharing between the parties. There are no secret parts that 'server cannot share with clients'.
Situation with GraphQL's SDL
In GraphQL things are not clear.
GraphQL SDL (type system/schema definition language) is an IDL for GraphQL (we state it explicitly).
Quote from spec:
So, there's SDL, may be used for something. Is it 'source of truth', complete description? not clear.
Then you read about Introspection, and discover that introspection returns less info than there can be in SDL file. It does not return 'applied attributes'. Seems strange.
A typical expectation for a new-comer would be: SDL and Introspection provides the same information, both a 'source of truth'. SDL is for humans, Intro for tools.
But in GraphQL its different. So I asked questions. Here are the answers I got from one of old timers in this WG:
Q: Why introspection and SDL do not match? What is a true description of API, source of truth?
A:
Later reading thru some discussions, I learned that exposing more through Introspection brings the risk exposing too much, some server-side secret, that is .... in server-side SDL. There is a server-side only SDL, with atributes and all. It is what we describe in the spec, full SDL, but client would never see it. If it is not shared, it is NOT part of communication protocol! I see some kind of 'hidden agenda' here.
Problem Statement
Problems:
Suggestion
SDL file for humans, Introspection for tools/apps
Beta Was this translation helpful? Give feedback.
All reactions