From 51ba05a79070ebb81f072d89d525c40df11376be Mon Sep 17 00:00:00 2001 From: "jeremy.meulemans" Date: Mon, 28 Jan 2019 13:53:49 -0500 Subject: [PATCH 01/10] Adding SQL Support documentation --- README.md | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 32900ecdf..fc634329a 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,7 @@ It's modeled after Python's `json.tool`, reading from stdin and writing to stdou * [\__count](#__count) * [The GraphQL schema](#the-graphql-schema) * [Execution model](#execution-model) + * [SQL Support](#sql-support) * [Miscellaneous](#miscellaneous) * [Expanding `@optional` vertex fields](#expanding-optional-vertex-fields) * [Optional `type_equivalence_hints` compilation parameter](#optional-type_equivalence_hints-parameter) @@ -80,12 +81,16 @@ A: No -- there are many existing frameworks for running a web server. We simply **Q: What databases and query languages does the compiler support?** -A: We currently support a single database, OrientDB version 2.2.28+, and two query languages +A: We currently support a single graph database, OrientDB version 2.2.28+, and two query languages that OrientDB supports: the OrientDB dialect of `gremlin`, and OrientDB's own custom SQL-like query language that we refer to as `MATCH`, after the name of its graph traversal operator. With OrientDB, `MATCH` should be the preferred choice for most users, since it tends to run faster than `gremlin`, and has other desirable properties. See the [Execution model](#execution-model) section for more details. + + Several relational databases including PostgreSQL, MySQL, Sqlite, + and Sql Server are also supported in a limited fashion, see the [SQL Support](#sql-support) + section for more details. **Q: Do you plan to support other databases / more GraphQL features in the future?** @@ -1135,6 +1140,20 @@ the opposite order: } ``` +## SQL Support +The following table outlines the subset of the GraphQL compiler features that are tested and +supported for various relational database flavor: + + +| Dialect | Supported Directives | Caveats | +| --------- | -------------------------------------- | ----------------------------------------------- | +| PostgreSQL | [@output](#output), [@filter](#filter) | [\__typename](#__typename) output metafield, [intersects](#intersects) filter, [has_edge_degree](#has_edge_degree) filter and [name_or_alias](#name_or_alias) filter unsupported| +| Sql Server | [@output](#output), [@filter](#filter) | [\__typename](#__typename) output metafield, [intersects](#intersects) filter, [has_edge_degree](#has_edge_degree) filter and [name_or_alias](#name_or_alias) filter unsupported| +| MySQL | [@output](#output), [@filter](#filter) | [\__typename](#__typename) output metafield, [intersects](#intersects) filter, [has_edge_degree](#has_edge_degree) filter and [name_or_alias](#name_or_alias) filter unsupported| +| MariaDB | [@output](#output), [@filter](#filter) | [\__typename](#__typename) output metafield, [intersects](#intersects) filter, [has_edge_degree](#has_edge_degree) filter and [name_or_alias](#name_or_alias) filter unsupported| +| Sqlite | [@output](#output), [@filter](#filter) | [\__typename](#__typename) output metafield, [intersects](#intersects) filter, [has_edge_degree](#has_edge_degree) filter and [name_or_alias](#name_or_alias) filter unsupported| + + ## Miscellaneous ### Expanding [`@optional`](#optional) vertex fields From 9caae1343249647ff8bb24e8b9e63329266fa28e Mon Sep 17 00:00:00 2001 From: "jeremy.meulemans" Date: Mon, 28 Jan 2019 13:57:45 -0500 Subject: [PATCH 02/10] Indicating that traversing edges isn't yet a thing --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index fc634329a..64979382a 100644 --- a/README.md +++ b/README.md @@ -1147,11 +1147,11 @@ supported for various relational database flavor: | Dialect | Supported Directives | Caveats | | --------- | -------------------------------------- | ----------------------------------------------- | -| PostgreSQL | [@output](#output), [@filter](#filter) | [\__typename](#__typename) output metafield, [intersects](#intersects) filter, [has_edge_degree](#has_edge_degree) filter and [name_or_alias](#name_or_alias) filter unsupported| -| Sql Server | [@output](#output), [@filter](#filter) | [\__typename](#__typename) output metafield, [intersects](#intersects) filter, [has_edge_degree](#has_edge_degree) filter and [name_or_alias](#name_or_alias) filter unsupported| -| MySQL | [@output](#output), [@filter](#filter) | [\__typename](#__typename) output metafield, [intersects](#intersects) filter, [has_edge_degree](#has_edge_degree) filter and [name_or_alias](#name_or_alias) filter unsupported| -| MariaDB | [@output](#output), [@filter](#filter) | [\__typename](#__typename) output metafield, [intersects](#intersects) filter, [has_edge_degree](#has_edge_degree) filter and [name_or_alias](#name_or_alias) filter unsupported| -| Sqlite | [@output](#output), [@filter](#filter) | [\__typename](#__typename) output metafield, [intersects](#intersects) filter, [has_edge_degree](#has_edge_degree) filter and [name_or_alias](#name_or_alias) filter unsupported| +| PostgreSQL | Root-only queries (no edges), [@output](#output), [@filter](#filter) | [\__typename](#__typename) output metafield, [intersects](#intersects) filter, [has_edge_degree](#has_edge_degree) filter and [name_or_alias](#name_or_alias) filter unsupported| +| Sql Server | Root-only queries (no edges), [@output](#output), [@filter](#filter) | [\__typename](#__typename) output metafield, [intersects](#intersects) filter, [has_edge_degree](#has_edge_degree) filter and [name_or_alias](#name_or_alias) filter unsupported| +| MySQL | Root-only queries (no edges), [@output](#output), [@filter](#filter) | [\__typename](#__typename) output metafield, [intersects](#intersects) filter, [has_edge_degree](#has_edge_degree) filter and [name_or_alias](#name_or_alias) filter unsupported| +| MariaDB | Root-only queries (no edges), [@output](#output), [@filter](#filter) | [\__typename](#__typename) output metafield, [intersects](#intersects) filter, [has_edge_degree](#has_edge_degree) filter and [name_or_alias](#name_or_alias) filter unsupported| +| Sqlite | Root-only queries (no edges), [@output](#output), [@filter](#filter) | [\__typename](#__typename) output metafield, [intersects](#intersects) filter, [has_edge_degree](#has_edge_degree) filter and [name_or_alias](#name_or_alias) filter unsupported| ## Miscellaneous From a11aff076d9bad9a69335a41523f1744083503a0 Mon Sep 17 00:00:00 2001 From: "jeremy.meulemans" Date: Mon, 28 Jan 2019 14:00:26 -0500 Subject: [PATCH 03/10] Fixing SQLite typo --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 64979382a..e8cfa87c6 100644 --- a/README.md +++ b/README.md @@ -88,8 +88,8 @@ A: We currently support a single graph database, OrientDB version 2.2.28+, and t faster than `gremlin`, and has other desirable properties. See the [Execution model](#execution-model) section for more details. - Several relational databases including PostgreSQL, MySQL, Sqlite, - and Sql Server are also supported in a limited fashion, see the [SQL Support](#sql-support) + Several relational databases including PostgreSQL, MySQL, SSQLite, + and Sql Server are also supported in a more limited fashion, see the [SQL Support](#sql-support) section for more details. **Q: Do you plan to support other databases / more GraphQL features in the future?** @@ -1151,7 +1151,7 @@ supported for various relational database flavor: | Sql Server | Root-only queries (no edges), [@output](#output), [@filter](#filter) | [\__typename](#__typename) output metafield, [intersects](#intersects) filter, [has_edge_degree](#has_edge_degree) filter and [name_or_alias](#name_or_alias) filter unsupported| | MySQL | Root-only queries (no edges), [@output](#output), [@filter](#filter) | [\__typename](#__typename) output metafield, [intersects](#intersects) filter, [has_edge_degree](#has_edge_degree) filter and [name_or_alias](#name_or_alias) filter unsupported| | MariaDB | Root-only queries (no edges), [@output](#output), [@filter](#filter) | [\__typename](#__typename) output metafield, [intersects](#intersects) filter, [has_edge_degree](#has_edge_degree) filter and [name_or_alias](#name_or_alias) filter unsupported| -| Sqlite | Root-only queries (no edges), [@output](#output), [@filter](#filter) | [\__typename](#__typename) output metafield, [intersects](#intersects) filter, [has_edge_degree](#has_edge_degree) filter and [name_or_alias](#name_or_alias) filter unsupported| +| SQLite | Root-only queries (no edges), [@output](#output), [@filter](#filter) | [\__typename](#__typename) output metafield, [intersects](#intersects) filter, [has_edge_degree](#has_edge_degree) filter and [name_or_alias](#name_or_alias) filter unsupported| ## Miscellaneous From 3e629ba962389265d45544a95fee6c727793fcab Mon Sep 17 00:00:00 2001 From: "jeremy.meulemans" Date: Mon, 28 Jan 2019 14:01:06 -0500 Subject: [PATCH 04/10] Flavor -> Flavors --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e8cfa87c6..55e62214c 100644 --- a/README.md +++ b/README.md @@ -1142,7 +1142,7 @@ the opposite order: ## SQL Support The following table outlines the subset of the GraphQL compiler features that are tested and -supported for various relational database flavor: +supported for various relational database flavors: | Dialect | Supported Directives | Caveats | From a356e3c3125761c718ef0d3a07eebaa84dc85799 Mon Sep 17 00:00:00 2001 From: "jeremy.meulemans" Date: Tue, 29 Jan 2019 10:27:31 -0500 Subject: [PATCH 05/10] Adding E2E SQL example --- README.md | 124 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) diff --git a/README.md b/README.md index 55e62214c..44505b170 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,9 @@ It's modeled after Python's `json.tool`, reading from stdin and writing to stdou * [The GraphQL schema](#the-graphql-schema) * [Execution model](#execution-model) * [SQL Support](#sql-support) + * [Configuring SQLAlchemy](#configuring-sqlalchemy) + * [End-To-End SQL Example](#end-to-end-sql-example) + * [Configuring SQL Database to Match Schema](#configuring-sql-database-to-match-schema) * [Miscellaneous](#miscellaneous) * [Expanding `@optional` vertex fields](#expanding-optional-vertex-fields) * [Optional `type_equivalence_hints` compilation parameter](#optional-type_equivalence_hints-parameter) @@ -1154,6 +1157,127 @@ supported for various relational database flavors: | SQLite | Root-only queries (no edges), [@output](#output), [@filter](#filter) | [\__typename](#__typename) output metafield, [intersects](#intersects) filter, [has_edge_degree](#has_edge_degree) filter and [name_or_alias](#name_or_alias) filter unsupported| +### Configuring SQLAlchemy +Support for relational databases is accomplished by compiling to SQLAlchemy core as an intermediate +language, and then relying on SQLAlchemy's compilation of the dialect specific SQL string to query +the target database. + +For the SQL backend, GraphQL types are assumed to have a SQL table of the same name, and with the +same properties. For example, a schema type +``` +type Animal { + name: String +} +``` +is expected to correspond to a SQLAlchemy table object of the same name (case-insensitive) like + +```python +from sqlalchemy import MetaData, Table, Column, String +# table for GraphQL type Animal +metadata = MetaData() +animal_table = Table( + 'animal', # name of table matches type name from schema + metadata, + Column('name', String(length=12)), # Animal.name field has corresponding 'name' column +) +``` + + +### End-To-End SQL Example +An end-to-end example including relevant GraphQL schema and SQLAlchemy engine preparation follows. + +Note this is intended to show the setup steps for the SQL backend of the Graphql compiler, and does +not represent best practices for configuring and running SQLAlchemy in a production system. Where +possible links to relevant SQLAlchemy documentation are included. + +```python +from graphql import parse +from graphql.utils.build_ast_schema import build_ast_schema +from sqlalchemy import MetaData, Table, Column, String, create_engine +from graphql_compiler.compiler.ir_lowering_sql.metadata import SqlMetadata +from graphql_compiler import compile_graphql_to_sql, insert_arguments_into_query + +# Step 1: Configure a GraphQL schema (note that this can also be done programmatically) +schema_text = ''' +schema { + query: RootSchemaQuery +} +# IMPORTANT NOTE: all compiler directives are expected here, but not shown to keep the example brief + +directive @filter(op_name: String!, value: [String!]!) on FIELD | INLINE_FRAGMENT + +directive @output(out_name: String!) on FIELD + +type Animal { + name: String +} +''' +schema = build_ast_schema(parse(schema_text)) + +# Step 2: For all GraphQL types, bind the corresponding SQLAlchemy Table to a SQLAlchemy metadata +# instance, using the expected naming detailed above. +# See https://docs.sqlalchemy.org/en/latest/core/metadata.html for more details on this step. +metadata = MetaData() +animal_table = Table( + 'animal', # name of table matches type name from schema + metadata, + # Animal.name schema field has corresponding 'name' column in animal table + Column('name', String(length=12)), +) + +# Step 3: Prepare a SQLAlchemy engine to query the target relational database. +# See https://docs.sqlalchemy.org/en/latest/core/engines.html for more detail on this step. +engine = create_engine('') + +# Step 4: Wrap the SQLAlchemy metadata and dialect as a SqlMetadata GraphQL compiler object +sql_metadata = SqlMetadata(engine.dialect, metadata) + +# Step 5: Prepare and compile a GraphQL query against the schema +graphql_query = ''' +{ + Animal { + name @output(out_name: "animal_name") + @filter(op_name: "in_collection", value:["$names"]) + } +} +''' +parameters = { + 'names': ['animal name 1', 'animal name 2'], +} + +compilation_result = compile_graphql_to_sql(schema, graphql_query, sql_metadata) +compilation_result = insert_arguments_into_query(compilation_result, parameters) + + +# Step 6: Execute compiled query against a SQLAlchemy engine/connection. +# See https://docs.sqlalchemy.org/en/latest/core/connections.html for more details. +query = compilation_result.query +query_results = [dict(result_proxy) for result_proxy in engine.execute(query)] +``` + +### Configuring SQL Database to Match Schema +For simplicity, the SQL backend expects an exact match between SQLAlchemy Tables and GraphQL types, +and between SQLAlchemy Columns and GraphQL fields. What if the table name or column name in the +database doesn't conform to these rules? Eventually the plan is to make this aspect of the +SQL backend more configurable. In the near-term, a possible way to address this is by using +SQL view. + +For example, suppose there is a table in the database called `animal_table` and it has a column +called `animal_name`. If the desired schema has type +``` +type Animal { + name: String +} +``` +Then this could be exposed via a view like: +```sql +CREATE VIEW animal AS + SELECT + animal_name AS name + FROM animal_table +``` +At this point, the `animal` view can be used in the SQLAlchemy Table for the purposes of compiling. + ## Miscellaneous ### Expanding [`@optional`](#optional) vertex fields From 27ab3bf9c673ef50d0e25e8ca63b0ccbaf9f0cb8 Mon Sep 17 00:00:00 2001 From: "jeremy.meulemans" Date: Fri, 8 Feb 2019 12:32:24 -0500 Subject: [PATCH 06/10] Addressing PR comments, fixing CompilerMetadata references --- README.md | 62 ++++++++++++++------------- graphql_compiler/__init__.py | 2 +- graphql_compiler/compiler/emit_sql.py | 4 +- 3 files changed, 36 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 44505b170..420d891a8 100644 --- a/README.md +++ b/README.md @@ -49,10 +49,10 @@ It's modeled after Python's `json.tool`, reading from stdin and writing to stdou * [\__count](#__count) * [The GraphQL schema](#the-graphql-schema) * [Execution model](#execution-model) - * [SQL Support](#sql-support) + * [SQL](#sql) * [Configuring SQLAlchemy](#configuring-sqlalchemy) * [End-To-End SQL Example](#end-to-end-sql-example) - * [Configuring SQL Database to Match Schema](#configuring-sql-database-to-match-schema) + * [Configuring the SQL Database to Match the GraphQL Schema](#configuring-the-sql-database-to-match-the-graphql-schema) * [Miscellaneous](#miscellaneous) * [Expanding `@optional` vertex fields](#expanding-optional-vertex-fields) * [Optional `type_equivalence_hints` compilation parameter](#optional-type_equivalence_hints-parameter) @@ -91,9 +91,9 @@ A: We currently support a single graph database, OrientDB version 2.2.28+, and t faster than `gremlin`, and has other desirable properties. See the [Execution model](#execution-model) section for more details. - Several relational databases including PostgreSQL, MySQL, SSQLite, - and Sql Server are also supported in a more limited fashion, see the [SQL Support](#sql-support) - section for more details. + Support for relational databases including PostgreSQL, MySQL, SQLite, + and Microsft Sql Server is a work in progress. A subset of compiler features are available for + these databases. See the [SQL](#sql) section for more details. **Q: Do you plan to support other databases / more GraphQL features in the future?** @@ -1034,7 +1034,7 @@ The compiler abides by the following principles: - When the database is queried with a compiled query string, its response must always be in the form of a list of results. - The precise format of each such result is defined by each compilation target separately. - - Both `gremlin` and `MATCH` return data in a tabular format, where each result is + - `gremlin`, `MATCH` and `SQL` return data in a tabular format, where each result is a row of the table, and fields marked for output are columns. - However, future compilation targets may have a different format. For example, each result may appear in the nested tree format used by the standard GraphQL specification. @@ -1143,22 +1143,21 @@ the opposite order: } ``` -## SQL Support -The following table outlines the subset of the GraphQL compiler features that are tested and -supported for various relational database flavors: +## SQL +The following table outlines GraphQL compiler features, and their support (if any) by various +relational database flavors: -| Dialect | Supported Directives | Caveats | -| --------- | -------------------------------------- | ----------------------------------------------- | -| PostgreSQL | Root-only queries (no edges), [@output](#output), [@filter](#filter) | [\__typename](#__typename) output metafield, [intersects](#intersects) filter, [has_edge_degree](#has_edge_degree) filter and [name_or_alias](#name_or_alias) filter unsupported| -| Sql Server | Root-only queries (no edges), [@output](#output), [@filter](#filter) | [\__typename](#__typename) output metafield, [intersects](#intersects) filter, [has_edge_degree](#has_edge_degree) filter and [name_or_alias](#name_or_alias) filter unsupported| -| MySQL | Root-only queries (no edges), [@output](#output), [@filter](#filter) | [\__typename](#__typename) output metafield, [intersects](#intersects) filter, [has_edge_degree](#has_edge_degree) filter and [name_or_alias](#name_or_alias) filter unsupported| -| MariaDB | Root-only queries (no edges), [@output](#output), [@filter](#filter) | [\__typename](#__typename) output metafield, [intersects](#intersects) filter, [has_edge_degree](#has_edge_degree) filter and [name_or_alias](#name_or_alias) filter unsupported| -| SQLite | Root-only queries (no edges), [@output](#output), [@filter](#filter) | [\__typename](#__typename) output metafield, [intersects](#intersects) filter, [has_edge_degree](#has_edge_degree) filter and [name_or_alias](#name_or_alias) filter unsupported| - +| Feature/Dialect | Required Edges | @filter | @output | @recurse | @fold | @optional | @output_source | +|----------------------|----------------|---------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------|----------|-------|-----------|----------------| +| PostgreSQL | No | Limited, [intersects](#intersects), [has_edge_degree](#has_edge_degree), and [name_or_alias](#name_or_alias) filter unsupported | Limited, [\__typename](#__typename) output metafield unsupported | No | No | No | No | +| SQLite | No | Limited, [intersects](#intersects), [has_edge_degree](#has_edge_degree), and [name_or_alias](#name_or_alias) filter unsupported | Limited, [\__typename](#__typename) output metafield unsupported | No | No | No | No | +| Microsoft SQL Server | No | Limited, [intersects](#intersects), [has_edge_degree](#has_edge_degree), and [name_or_alias](#name_or_alias) filter unsupported | Limited, [\__typename](#__typename) output metafield unsupported | No | No | No | No | +| MySQL | No | Limited, [intersects](#intersects), [has_edge_degree](#has_edge_degree), and [name_or_alias](#name_or_alias) filter unsupported | Limited, [\__typename](#__typename) output metafield unsupported | No | No | No | No | +| MariaDB | No | Limited, [intersects](#intersects), [has_edge_degree](#has_edge_degree), and [name_or_alias](#name_or_alias) filter unsupported | Limited, [\__typename](#__typename) output metafield unsupported | No | No | No | No | ### Configuring SQLAlchemy -Support for relational databases is accomplished by compiling to SQLAlchemy core as an intermediate +Relational databases are supported by compiling to SQLAlchemy core as an intermediate language, and then relying on SQLAlchemy's compilation of the dialect specific SQL string to query the target database. @@ -1169,7 +1168,8 @@ type Animal { name: String } ``` -is expected to correspond to a SQLAlchemy table object of the same name (case-insensitive) like +is expected to correspond to a SQLAlchemy table object of the same name, case insensitive. For this +schema type this could look like: ```python from sqlalchemy import MetaData, Table, Column, String @@ -1178,17 +1178,20 @@ metadata = MetaData() animal_table = Table( 'animal', # name of table matches type name from schema metadata, - Column('name', String(length=12)), # Animal.name field has corresponding 'name' column + Column('name', String(length=12)), # Animal.name GraphQL field has corresponding 'name' column ) ``` +If a table of the schema type name does not exist, an exception will be raised at compile time. See +[Configuring the SQL Database to Match the GraphQL Schema](#configuring-the-sql-database-to-match-the-graphql-schema) +for a possible option to resolve such naming discrepancies. + ### End-To-End SQL Example An end-to-end example including relevant GraphQL schema and SQLAlchemy engine preparation follows. -Note this is intended to show the setup steps for the SQL backend of the Graphql compiler, and does -not represent best practices for configuring and running SQLAlchemy in a production system. Where -possible links to relevant SQLAlchemy documentation are included. +This is intended to show the setup steps for the SQL backend of the GraphQL compiler, and +does not represent best practices for configuring and running SQLAlchemy in a production system. ```python from graphql import parse @@ -1206,6 +1209,8 @@ schema { directive @filter(op_name: String!, value: [String!]!) on FIELD | INLINE_FRAGMENT +# < ... more directives here ... > + directive @output(out_name: String!) on FIELD type Animal { @@ -1214,8 +1219,8 @@ type Animal { ''' schema = build_ast_schema(parse(schema_text)) -# Step 2: For all GraphQL types, bind the corresponding SQLAlchemy Table to a SQLAlchemy metadata -# instance, using the expected naming detailed above. +# Step 2: For all GraphQL types, bind all corresponding SQLAlchemy Tables to a single SQLAlchemy +# metadata instance, using the expected naming detailed above. # See https://docs.sqlalchemy.org/en/latest/core/metadata.html for more details on this step. metadata = MetaData() animal_table = Table( @@ -1237,7 +1242,7 @@ graphql_query = ''' { Animal { name @output(out_name: "animal_name") - @filter(op_name: "in_collection", value:["$names"]) + @filter(op_name: "in_collection", value: ["$names"]) } } ''' @@ -1248,19 +1253,18 @@ parameters = { compilation_result = compile_graphql_to_sql(schema, graphql_query, sql_metadata) compilation_result = insert_arguments_into_query(compilation_result, parameters) - # Step 6: Execute compiled query against a SQLAlchemy engine/connection. # See https://docs.sqlalchemy.org/en/latest/core/connections.html for more details. query = compilation_result.query query_results = [dict(result_proxy) for result_proxy in engine.execute(query)] ``` -### Configuring SQL Database to Match Schema +### Configuring the SQL Database to Match the GraphQL Schema For simplicity, the SQL backend expects an exact match between SQLAlchemy Tables and GraphQL types, and between SQLAlchemy Columns and GraphQL fields. What if the table name or column name in the database doesn't conform to these rules? Eventually the plan is to make this aspect of the SQL backend more configurable. In the near-term, a possible way to address this is by using -SQL view. +SQL views. For example, suppose there is a table in the database called `animal_table` and it has a column called `animal_name`. If the desired schema has type diff --git a/graphql_compiler/__init__.py b/graphql_compiler/__init__.py index 17bffbeee..9c39a2d0f 100644 --- a/graphql_compiler/__init__.py +++ b/graphql_compiler/__init__.py @@ -67,7 +67,7 @@ def graphql_to_sql(schema, graphql_query, parameters, compiler_metadata, schema: GraphQL schema object describing the schema of the graph to be queried graphql_query: the GraphQL query to compile to SQL, as a string parameters: dict, mapping argument name to its value, for every parameter the query expects. - compiler_metadata: CompilerMetadata object, provides SQLAlchemy specific backend + compiler_metadata: SqlMetadata object, provides SQLAlchemy specific backend information type_equivalence_hints: optional dict of GraphQL interface or type -> GraphQL union. Used as a workaround for GraphQL's lack of support for diff --git a/graphql_compiler/compiler/emit_sql.py b/graphql_compiler/compiler/emit_sql.py index dc504394f..a043269a3 100644 --- a/graphql_compiler/compiler/emit_sql.py +++ b/graphql_compiler/compiler/emit_sql.py @@ -20,7 +20,7 @@ # renamed status. This tuple is used to construct the query outputs, and track when a name # changes due to collapsing into a CTE. 'query_path_to_output_fields', - # 'compiler_metadata': CompilerMetadata, SQLAlchemy metadata about Table objects, and + # 'compiler_metadata': SqlMetadata, SQLAlchemy metadata about Table objects, and # further backend specific configuration. 'compiler_metadata', )) @@ -31,7 +31,7 @@ def emit_code_from_ir(sql_query_tree, compiler_metadata): Args: sql_query_tree: SqlQueryTree, tree representation of the query to emit. - compiler_metadata: CompilerMetadata, SQLAlchemy specific metadata. + compiler_metadata: SqlMetadata, SQLAlchemy specific metadata. Returns: SQLAlchemy Query From ed79c9994f5465de9d30cc308064b8a1a404cea2 Mon Sep 17 00:00:00 2001 From: "jeremy.meulemans" Date: Mon, 11 Feb 2019 09:44:38 -0500 Subject: [PATCH 07/10] Fixing MSFT reference --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0da96f7a3..68c39baf9 100644 --- a/README.md +++ b/README.md @@ -92,7 +92,7 @@ A: We currently support a single graph database, OrientDB version 2.2.28+, and t [Execution model](#execution-model) section for more details. Support for relational databases including PostgreSQL, MySQL, SQLite, - and Microsft Sql Server is a work in progress. A subset of compiler features are available for + and Microsoft Sql Server is a work in progress. A subset of compiler features are available for these databases. See the [SQL](#sql) section for more details. **Q: Do you plan to support other databases / more GraphQL features in the future?** From 25f60f0aac9f5b89654a69a421d583da306044f1 Mon Sep 17 00:00:00 2001 From: "jeremy.meulemans" Date: Tue, 12 Feb 2019 09:10:16 -0500 Subject: [PATCH 08/10] Fixing typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 68c39baf9..50398d8bb 100644 --- a/README.md +++ b/README.md @@ -92,7 +92,7 @@ A: We currently support a single graph database, OrientDB version 2.2.28+, and t [Execution model](#execution-model) section for more details. Support for relational databases including PostgreSQL, MySQL, SQLite, - and Microsoft Sql Server is a work in progress. A subset of compiler features are available for + and Microsoft SQL Server is a work in progress. A subset of compiler features are available for these databases. See the [SQL](#sql) section for more details. **Q: Do you plan to support other databases / more GraphQL features in the future?** From 13e595823b75dd57a4cd45ccc75915e49e19ee69 Mon Sep 17 00:00:00 2001 From: "jeremy.meulemans" Date: Tue, 19 Feb 2019 10:41:17 -0500 Subject: [PATCH 09/10] Addressing Micheala's CR --- README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 50398d8bb..e5a652030 100644 --- a/README.md +++ b/README.md @@ -1213,7 +1213,7 @@ from graphql import parse from graphql.utils.build_ast_schema import build_ast_schema from sqlalchemy import MetaData, Table, Column, String, create_engine from graphql_compiler.compiler.ir_lowering_sql.metadata import SqlMetadata -from graphql_compiler import compile_graphql_to_sql, insert_arguments_into_query +from graphql_compiler import graphql_to_sql # Step 1: Configure a GraphQL schema (note that this can also be done programmatically) schema_text = ''' @@ -1224,7 +1224,7 @@ schema { directive @filter(op_name: String!, value: [String!]!) on FIELD | INLINE_FRAGMENT -# < ... more directives here ... > +# < more directives here, see the GraphQL schema section of this README for more details. > directive @output(out_name: String!) on FIELD @@ -1265,8 +1265,7 @@ parameters = { 'names': ['animal name 1', 'animal name 2'], } -compilation_result = compile_graphql_to_sql(schema, graphql_query, sql_metadata) -compilation_result = insert_arguments_into_query(compilation_result, parameters) +compilation_result = graphql_to_sql(schema, graphql_query, parameters, sql_metadata) # Step 6: Execute compiled query against a SQLAlchemy engine/connection. # See https://docs.sqlalchemy.org/en/latest/core/connections.html for more details. From 86203ed6161d0fc5a2f5d146afb3f38bcc62147d Mon Sep 17 00:00:00 2001 From: "jeremy.meulemans" Date: Thu, 21 Feb 2019 09:54:40 -0500 Subject: [PATCH 10/10] Recommit to trigger the final coverage check