Skip to content
This repository has been archived by the owner on Oct 21, 2022. It is now read-only.

preserve original formatting generated by schema_printer #68

Merged

Conversation

SaulTigh
Copy link
Contributor

@SaulTigh SaulTigh commented Jun 30, 2022

current behaviour of get_sdl is to strip all line breaks, which then forces us to recreate schema with weird regex hooks.
this should fix this behaviour.

@erebus1
Copy link
Collaborator

erebus1 commented Jun 30, 2022

@SaulTigh Thanks for your PR!
Do you have any ideas why this replace was added initially?
Just to doublecheck that it'll not harm overall logic

@SaulTigh
Copy link
Contributor Author

SaulTigh commented Jul 1, 2022

@erebus1 i guess originally it was added to ease working with regex, but it works without it well enough.
in our internal project, we had to restore schema formatting like this:

def get_schema_sdl() -> str:
    sdl = schema.execute("query {_service { sdl }}").data['_service']['sdl'].strip()

    sdl = sdl.replace('   ', '\n  ')
    sdl = re.sub(r'} +(type|input|enum|scalar|union|extend type) ', r'\n}\n\n\1 ', sdl)
    sdl = re.sub(r'scalar (\w+) +', r'scalar \1\n\n', sdl)
    sdl = re.sub(r' +\n', '\n', sdl)

    return sdl

after removing that line function can look like this:

def get_schema_sdl() -> str:
    return schema.execute("query {_service { sdl }}").data['_service']['sdl'].strip()

@erebus1 erebus1 self-requested a review July 1, 2022 07:27
@SaulTigh SaulTigh added enhancement New feature or request python Pull requests that update Python code labels Jul 6, 2022
@SaulTigh SaulTigh requested a review from sakhatskyi July 6, 2022 14:14
@SaulTigh SaulTigh closed this Jul 22, 2022
@SaulTigh SaulTigh reopened this Aug 3, 2022
@SaulTigh SaulTigh merged commit 4904f43 into preply:master Aug 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request python Pull requests that update Python code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants