Created
January 31, 2024 06:45
-
-
Save colonelpanic8/04172b1452374b0c46a3cf44ea4e8204 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from gql import dsl | |
def all_gql_fields(the_value): | |
if isinstance(the_value, dsl.DSLType): | |
underlying_type = the_value._type | |
if isinstance(the_value, dsl.DSLField): | |
underlying_type = un_of_type(the_value.field.type) | |
if not hasattr(underlying_type, "fields"): | |
return the_value | |
selections = [] | |
for key in underlying_type.fields.keys(): | |
if key == "shots": | |
import ipdb | |
ipdb.set_trace() | |
selected_field = getattr(the_value, key) | |
selections.append(all_gql_fields(selected_field)) | |
if isinstance(the_value, dsl.DSLType): | |
return selections | |
return the_value.select(*selections) | |
def un_of_type(value): | |
if hasattr(value, "of_type"): | |
return un_of_type(value.of_type) | |
return value |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment