@@ -226,56 +226,63 @@ def _create_sql_schema_info(
226226)
227227
228228
229- # Complete schema information sufficient to compile GraphQL queries to SQLAlchemy
230- #
231- # It describes the tables that correspond to each type (object type or interface type),
232- # and gives instructions on how to perform joins for each vertex field. The property fields on each
233- # type are implicitly mapped to columns with the same name on the corresponding table.
234- #
235- # NOTES:
236- # - RootSchemaQuery is a special type that does not need a corresponding table.
237- # - Builtin types like __Schema, __Type, etc. don't need corresponding tables.
238- # - Builtin fields like _x_count do not need corresponding columns.
239- SQLAlchemySchemaInfo = namedtuple (
240- "SQLAlchemySchemaInfo" ,
241- (
242- # GraphQLSchema
243- "schema" ,
244- # optional dict of GraphQL interface or type -> GraphQL union.
245- # Used as a workaround for GraphQL's lack of support for
246- # inheritance across "types" (i.e. non-interfaces), as well as a
247- # workaround for Gremlin's total lack of inheritance-awareness.
248- # The key-value pairs in the dict specify that the "key" type
249- # is equivalent to the "value" type, i.e. that the GraphQL type or
250- # interface in the key is the most-derived common supertype
251- # of every GraphQL type in the "value" GraphQL union.
252- # Recursive expansion of type equivalence hints is not performed,
253- # and only type-level correctness of this argument is enforced.
254- # See README.md for more details on everything this parameter does.
255- # *****
256- # Be very careful with this option, as bad input here will
257- # lead to incorrect output queries being generated.
258- # *****
259- "type_equivalence_hints" ,
260- # sqlalchemy.engine.interfaces.Dialect, specifying the dialect we are compiling for
261- # (e.g. sqlalchemy.dialects.mssql.dialect()).
262- "dialect" ,
263- # dict mapping every graphql object type or interface type name in the schema to
264- # a sqlalchemy table. Column types that do not exist for this dialect are not allowed.
265- # All tables are expected to have primary keys.
266- "vertex_name_to_table" ,
267- # dict mapping every graphql object type or interface type name in the schema to:
268- # dict mapping every vertex field name at that type to a JoinDescriptor. The
269- # tables the join is to be performed on are not specified. They are inferred from
270- # the schema and the tables dictionary.
271- "join_descriptors" ,
272- ),
273- )
229+ @dataclass
230+ class SQLAlchemySchemaInfo :
231+ """Complete schema information sufficient to compile GraphQL queries to SQLAlchemy.
232+
233+ It describes the tables that correspond to each type (object type or interface type),
234+ and gives instructions on how to perform joins for each vertex field. The property fields on
235+ each type are implicitly mapped to columns with the same name on the corresponding table.
236+
237+ Notes:
238+ - RootSchemaQuery is a special type that does not need a corresponding table.
239+ - Builtin types like __Schema, __Type, etc. don't need corresponding tables.
240+ - Builtin fields like _x_count do not need corresponding columns.
241+
242+ TODO: This class is essentially the same as SQLSchemaInfo. SQLSchemaInfo is part of an
243+ incomplete refactor started in
244+ https://github.com/kensho-technologies/graphql-compiler/pull/714
245+ SQLAlchemySchemaInfo is currently used to compile GraphQL to SQL while CommonSchemaInfo
246+ is currently used to compile GraphQL to match, gremlin, and cypher.
247+ """
248+
249+ schema : GraphQLSchema
250+
251+ # Optional dict of GraphQL interface or type -> GraphQL union.
252+ # Used as a workaround for GraphQL's lack of support for
253+ # inheritance across "types" (i.e. non-interfaces), as well as a
254+ # workaround for Gremlin's total lack of inheritance-awareness.
255+ # The key-value pairs in the dict specify that the "key" type
256+ # is equivalent to the "value" type, i.e. that the GraphQL type or
257+ # interface in the key is the most-derived common supertype
258+ # of every GraphQL type in the "value" GraphQL union.
259+ # Recursive expansion of type equivalence hints is not performed,
260+ # and only type-level correctness of this argument is enforced.
261+ # See README.md for more details on everything this parameter does.
262+ # *****
263+ # Be very careful with this option, as bad input here will
264+ # lead to incorrect output queries being generated.
265+ # *****
266+ type_equivalence_hints : Optional [TypeEquivalenceHintsType ]
267+
268+ # Specifying the SQL Dialect.
269+ dialect : Dialect
270+
271+ # Mapping every GraphQL object or interface type name in the schema to the corresponding
272+ # SQLAlchemy table. Column types that do not exist for this dialect are not allowed.
273+ # All tables are expected to have primary keys.
274+ vertex_name_to_table : Dict [str , sqlalchemy .Table ]
275+
276+ # Mapping every GraphQL object or interface type name in the schema to:
277+ # dict mapping every vertex field name at that type to a JoinDescriptor. The
278+ # tables the join is to be performed on are not specified. They are inferred from
279+ # the schema and the tables dictionary.
280+ join_descriptors : Dict [str , Dict [str , JoinDescriptor ]]
274281
275282
276283def make_sqlalchemy_schema_info (
277284 schema : GraphQLSchema ,
278- type_equivalence_hints : TypeEquivalenceHintsType ,
285+ type_equivalence_hints : Optional [ TypeEquivalenceHintsType ] ,
279286 dialect : Dialect ,
280287 vertex_name_to_table : Dict [str , sqlalchemy .Table ],
281288 join_descriptors : Dict [str , Dict [str , JoinDescriptor ]],
0 commit comments