strawberry
strawberry copied to clipboard
Add SDL to strawberry conversion tool
It would be nice to have a command to convert an SDL to strawberry types, something like:
type User {
name: String!
}
type Query {
user: User
}
$ strawberry import-schema path.grapqhl
import typing
import strawberry
@strawberry.type
class User:
name: str
@strawberry.type
class Query:
user: typing.Optional[User]
This should support description and directives if possible :)
@patrick91 I want to work on this. How to get started on this?
@Jatinbalodhi96 I'll assign you to this issue :)
We have a small contribution guide here: https://github.com/strawberry-graphql/strawberry/blob/master/CONTRIBUTING.md#contributing-to-code
We also have a cli setup (which should be refactored I reckon): https://github.com/strawberry-graphql/strawberry/blob/master/strawberry/cli/init.py
So maybe you can start from that, what do you think?
thanks, @patrick91 I followed the guide but while running I faced two errors:
- [x] -
poetry run pytest tests
it gives meModuleNotFoundError: No module named 'termios'
error, after searching figure out that this library is for Linux only. - [x]
Whileimport strawberry
I gotno Module named 'graphql'
even I already ran poetry install which ran. - [ ] Unable to install graphql by running
poetry add graphql
gettingbuilding 'graphql_ext' extension error: unknown file type '.pyx' (from 'graphql/graphql_ext.pyx')
error
@Jatinbalodhi96 uh, never seen that error, what os and python version are using?
I'm using python 3.7 on windows 10, Now I'm able to run
- I'm able run strawberry now but i installed graphql seperately using
pipenv install --pre "graphql-core>=3a"
The error I sent earlier was because I was installing graphql using poetry add graphql
, I'm not sure if it works same for all.
@Jatinbalodhi96 oh interest, I never tried strawberry or event GraphQL core on windows, I'll see if I can add tests for that, I don't have a windows machine at the moment, so it might take me a while to test this :)
@patrick91 I've never used poetry before but is this correct way to build the dev version.
because I'm unable to run strawberry cli, but able to import strawberry.
@Jatinbalodhi96 yes :)
can you try with
poetry run strawberry
?
@patrick91 thanks this command run cli, but also I'm unable to import strawberry if I'm outside the directory, so like we do with pip for dependency installation pip install -e .
@Jatinbalodhi96 yes, poetry works a bit differently than pip, here's the docs on add: https://poetry.eustace.io/docs/cli/#add
do use it like pip install -e .
you need another poetry project as far as I understand :)
Hey, I'm interested in working on this too, this would be my first contribution ever... Is it possible for two people to be working the same issue?
@srbiotik no one is working on this at the moment, feel free to try! Ping me if you need some help 😉
@patrick91 Thanks a bunch, can't wait to sink my teeth into this!
@patrick91 Hey, I'm implementing an optional recursive parameter for resolving import statements. This would allow for large schemes to be split up into files and still get parsed without calling the command multiple times. What do you think about this?
@srbiotik large graphql schemas? that's interesting!
Personally I'd focus on being able to import a whole schema (even if it is one single file) and then add the support for import statements :)
@patrick91 I'm working on distinguishing required fields from optional.
I approached the problem by comparing swapi graphql schema and split it into files which are located at tests/cli/helpers
folder, since I can compare my output to the your swapi repository. There is one thing that kind of bugs me, why do some optional fields have = None
and others not?
When I look at the SDL there is no difference between them, although I see you made the swapi some 10 months ago so it's possible there has been some change in the SDL since then.
The swapi repository I've worked on is quite outdated 😊
Anyway, the main reason there's = None
in some places is because dataclasses don't set a default value for the field passed as optional:
It shouldn't make a difference for the SDL though, regarding SDL to Strawberry types, maybe we can put an option that adds = None
to optional fields?
Sure no problem, already implemented that, I'm wondering though about the description of the optional field. If a field has a description doesn't it need :
= strawberry.field( name="originalFieldName", description="Some clear description.")
Further more, I think i should add a name argument if the snake_case version of the field name differs from the original name.
One more question, in the swapi I never saw an optional field with a custom type
object that has None
assigned to it, is that a preference or a necessity?
What about the strawberry.ID
type is it legal to assign a description to it?
One more question, in the swapi I never saw an optional field with a custom type object that has None assigned to it, is that a preference or a necessity?
I think it is not have = None
:)
What about the strawberry.ID type is it legal to assign a description to it?
ID is usually self explicatory, but we should be able to do this:
x: strawberry.ID = strawberry.field(description='this is a legacy id')
``
Hey @patrick91 sorry for not being very active on this for a while, I've been buried at work an life :). So, I am up to a point where I could use somebody with more xp to look at what I've done so far, so what is the procedure how do present my work so far?
@srbiotik can you do a PR? we can also chat on discord if you want :) https://discord.gg/ZkRTEJQ
Hello, I'd be interested in helping with this if you need some peer review
Hello, I'd be interested in helping with this if you need some peer review
Yeah I need some help with this :). Thanks!
Do you have your code hosted in github so we can review it together?
@srbiotik any updates on this? I might need to implement it soon for something I'm working on, don't want to waste your time 😊
Hey, sorry for being passive about this I've been entangled by some work stuff. I'll push my version of code so far at this repository, you can run a test from the ./tests/cli/test_import_schema.py
there are some test gql files in the ./tests/cli/helpers/type
which you can change through the SPECIFIC_TYPE
and SPECIFIC_SCHEMA
constants in the test file. The resulting output should be located in the tests/cli/helpers/output
. All the work done in this was some months ago so I need to browse it a bit to remember... I'll be joining the discord chanell tomorrow so we can chat about it there!
P.S. Be gentle, it's my first contribution :)