-
Notifications
You must be signed in to change notification settings - Fork 107
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
Parsing schema definition language #126
Comments
What is the best way to use Youshido/GraphQL and do GraphQL mocking? It seems if the schema could be parsed from a schema file as suggested here then you could use graphql-tools to mock your schema based on it and then this schema file would be single "truth" for both the application and the mock. Alternatively, is there a way to dump the PHP-based schema to a GraphQL standard format schema file? That would work too I think although it wouldn't help much if you were trying to develop your frontend before the backend exists fully. |
I'm not sure that parsing a schema definition on the server side does make sense - it would be missing the one vital point: how to actually retrieve the data (from whatever data source). The schema definition used by the client does not and should not contain the logic on how to do so. That being said, there are many ways on how to handle schema generation for clients. In the end, they simply all contain the result of an introspection query (like the one GraphiQL sends, which is from a server's perspective just any regular client). For PHPStorm, there is this plugin for generating the schema file. This same process of course can be used to have some simple mock server too. The libraries examples contain quite a few examples on how to have simple mocked servers. Yet the principle of keeping the schema file up to date is always the same. |
@fritz-gerneth I don't follow: Why do you say a schema is used by the client only? I don't see how building a schema with php and key-valued arrays is any different than parsing a file. Neither defines data retrieval, but only structure and messaging. Implementation is out of scope in both cases. |
If you check apollo, they use GraphQL type language to define the schema, then js code to define implementations of messages: http://dev.apollodata.com/tools/graphql-tools/generate-schema.html Last step looks kind of like what I'm suggesting: based on this schema file and this implementation, make an |
@colinmollenhour I guess the fastest way to do so is to create your own "DataResolver" and start passing it around to resolvers inside your fields. It's quite easy to do and will get your frontend a working version of the GraphQL Schema. @guiwoda The last thought is to make it so we read/parse GraphQL Schema Language format and generate "base" classes that you can extend to set resolvers |
I'm not a fan of code generation tools, but I guess that's the easiest way of reusing your existing schema code. 👍 |
@guiwoda I wasn't aware of that tool by apollo. We're only using the apollo-angular client on our end :) Personally I an not a fan of this approach (it decouples the type & implementation of the server side) but I can see the intention and use behind this. For apollo, even on the client, it certainly might be helpful to have a schema in written in javascript. But I think it should be the server to generate it, not the client to provide it for the server. So personally I'd go down the road to have some simple CLI tool to generate the |
I love the way the schema is built programmatically as it will work great in modular and dynamic systems where fields are dynamic and modules can add new root-level and type-level fields using event observers and such. I think the apollo approach of having schema and resolvers defined separately is not so great in this case. |
For our project we recently built out a system for programatically generating the server-side graph. If anyone is looking for ideas you can find an example here. It's not quite what you were asking about but we chose this approach because it has a good balance between development speed and it's verifiable against an existing spec. We thought about making it standalone but it has quite tight coupling to some of our features and the structure of our GraphQL and we just don't have the time to generalize it. We also have a requirement to support multiple client interfaces (e.g. GraphQL, REST) in the near future so this all gets processed in to an agnostic format; although the format of the Our workflow currently consists of the front and back-end teams coming together to agree on a GraphQL schema for a feature and describing it as a We found that once you get past a certain size or complexity in your graph, the time it takes to implement it by hand through the object structure provided by this project becomes unmanageable. I think code generation is going to be a must for most projects. |
Is there any way to parse a Schema Definition Language file with this library?
I'd rather write type definitions the GraphQL way than using php arrays and custom-made objects, so that my definitions are valid as long as the GraphQL spec remains compatible.
I can't find any example that does something like:
The text was updated successfully, but these errors were encountered: