@@ -226,56 +226,62 @@ def _create_sql_schema_info(
226
226
)
227
227
228
228
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
+ TODO: This class is essentially the same as SQLSchemaInfo. SQLSchemaInfo is part of an
242
+ incomplete refactor started in
243
+ https://github.com/kensho-technologies/graphql-compiler/pull/714
244
+ SQLAlchemySchemaInfo is currently used to compile GraphQL to SQL while CommonSchemaInfo
245
+ is currently used to compile GraphQL to match, gremlin, and cypher.
246
+ """
247
+
248
+ schema : GraphQLSchema
249
+
250
+ # Optional dict of GraphQL interface or type -> GraphQL union.
251
+ # Used as a workaround for GraphQL's lack of support for
252
+ # inheritance across "types" (i.e. non-interfaces), as well as a
253
+ # workaround for Gremlin's total lack of inheritance-awareness.
254
+ # The key-value pairs in the dict specify that the "key" type
255
+ # is equivalent to the "value" type, i.e. that the GraphQL type or
256
+ # interface in the key is the most-derived common supertype
257
+ # of every GraphQL type in the "value" GraphQL union.
258
+ # Recursive expansion of type equivalence hints is not performed,
259
+ # and only type-level correctness of this argument is enforced.
260
+ # See README.md for more details on everything this parameter does.
261
+ # *****
262
+ # Be very careful with this option, as bad input here will
263
+ # lead to incorrect output queries being generated.
264
+ # *****
265
+ type_equivalence_hints : Optional [TypeEquivalenceHintsType ]
266
+
267
+ # Specifying the SQL Dialect.
268
+ dialect : Dialect
269
+
270
+ # Mapping every GraphQL object or interface type name in the schema to the corresponding
271
+ # SQLAlchemy table. Column types that do not exist for this dialect are not allowed.
272
+ # All tables are expected to have primary keys.
273
+ vertex_name_to_table : Dict [str , sqlalchemy .Table ]
274
+
275
+ # Mapping every GraphQL object or interface type name in the schema to:
276
+ # dict mapping every vertex field name at that type to a JoinDescriptor. The
277
+ # tables the join is to be performed on are not specified. They are inferred from
278
+ # the schema and the tables dictionary.
279
+ join_descriptors : Dict [str , Dict [str , JoinDescriptor ]]
274
280
275
281
276
282
def make_sqlalchemy_schema_info (
277
283
schema : GraphQLSchema ,
278
- type_equivalence_hints : TypeEquivalenceHintsType ,
284
+ type_equivalence_hints : Optional [ TypeEquivalenceHintsType ] ,
279
285
dialect : Dialect ,
280
286
vertex_name_to_table : Dict [str , sqlalchemy .Table ],
281
287
join_descriptors : Dict [str , Dict [str , JoinDescriptor ]],
0 commit comments