mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-09-21 07:28:26 +03:00
fix(#8904): Make BigQuery Computed Fields arguments optional
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5909 GitOrigin-RevId: 0d7c7de273c27bbd2338f42253754be0a06ea66e
This commit is contained in:
parent
85cfd91908
commit
26cdc03aa4
@ -420,12 +420,6 @@ bqComputedField sourceName ComputedFieldInfo {..} tableName tableInfo = runMaybe
|
||||
ComputedFieldFunction 'BigQuery ->
|
||||
SchemaT r m (InputFieldsParser n (FunctionArgsExp 'BigQuery (IR.UnpreparedValue 'BigQuery)))
|
||||
computedFieldFunctionArgs ComputedFieldFunction {..} = do
|
||||
let fieldName = Name._args
|
||||
fieldDesc =
|
||||
G.Description $
|
||||
"input parameters for computed field "
|
||||
<> _cfiName <<> " defined on table " <>> tableName
|
||||
|
||||
objectName <-
|
||||
mkTypename =<< do
|
||||
computedFieldGQLName <- textToName $ computedFieldNameToText _cfiName
|
||||
@ -436,12 +430,21 @@ bqComputedField sourceName ComputedFieldInfo {..} tableName tableInfo = runMaybe
|
||||
|
||||
argumentParsers <- sequenceA <$> forM userInputArgs parseArgument
|
||||
|
||||
let objectParser =
|
||||
P.object objectName Nothing argumentParsers `P.bind` \inputArguments -> do
|
||||
let tableColumnInputs = Map.map BigQuery.AETableColumn $ Map.mapKeys getFuncArgNameTxt _cffComputedFieldImplicitArgs
|
||||
pure $ FunctionArgsExp mempty $ Map.fromList inputArguments <> tableColumnInputs
|
||||
let userArgsParser = P.object objectName Nothing argumentParsers
|
||||
|
||||
pure $ P.field fieldName (Just fieldDesc) objectParser
|
||||
let fieldDesc =
|
||||
G.Description $
|
||||
"input parameters for computed field "
|
||||
<> _cfiName <<> " defined on table " <>> tableName
|
||||
|
||||
argsField
|
||||
| null userInputArgs = P.fieldOptional Name._args (Just fieldDesc) userArgsParser
|
||||
| otherwise = Just <$> P.field Name._args (Just fieldDesc) userArgsParser
|
||||
|
||||
pure $
|
||||
argsField `P.bindFields` \maybeInputArguments -> do
|
||||
let tableColumnInputs = Map.map BigQuery.AETableColumn $ Map.mapKeys getFuncArgNameTxt _cffComputedFieldImplicitArgs
|
||||
pure $ FunctionArgsExp mempty $ maybe mempty Map.fromList maybeInputArguments <> tableColumnInputs
|
||||
|
||||
parseArgument :: BigQuery.FunctionArgument -> SchemaT r m (InputFieldsParser n (Text, BigQuery.ArgumentExp (IR.UnpreparedValue 'BigQuery)))
|
||||
parseArgument arg = do
|
||||
|
@ -130,6 +130,25 @@ setupFunctions testEnv =
|
||||
BigQuery.runSql_ $
|
||||
T.unpack $
|
||||
"DROP TABLE FUNCTION " <> fetch_articles schemaName <> ";"
|
||||
},
|
||||
Fixture.SetupAction
|
||||
{ Fixture.setupAction =
|
||||
BigQuery.runSql_ $
|
||||
T.unpack $
|
||||
T.unwords $
|
||||
[ "CREATE TABLE FUNCTION ",
|
||||
fetch_articles_no_user_args_returns_table schemaName,
|
||||
"(a_id INT64)",
|
||||
"AS (",
|
||||
"SELECT t.* FROM",
|
||||
articleTableSQL,
|
||||
"AS t WHERE t.author_id = a_id",
|
||||
");"
|
||||
],
|
||||
Fixture.teardownAction = \_ ->
|
||||
BigQuery.runSql_ $
|
||||
T.unpack $
|
||||
"DROP TABLE FUNCTION " <> fetch_articles_no_user_args_returns_table schemaName <> ";"
|
||||
}
|
||||
]
|
||||
|
||||
@ -137,6 +156,10 @@ fetch_articles_returns_table :: SchemaName -> T.Text
|
||||
fetch_articles_returns_table schemaName =
|
||||
unSchemaName schemaName <> ".fetch_articles_returns_table"
|
||||
|
||||
fetch_articles_no_user_args_returns_table :: SchemaName -> T.Text
|
||||
fetch_articles_no_user_args_returns_table schemaName =
|
||||
unSchemaName schemaName <> ".fetch_articles_no_user_args_returns_table"
|
||||
|
||||
fetch_articles :: SchemaName -> T.Text
|
||||
fetch_articles schemaName =
|
||||
unSchemaName schemaName <> ".fetch_articles"
|
||||
@ -212,6 +235,41 @@ setupMetadata testEnv =
|
||||
name: author
|
||||
|]
|
||||
},
|
||||
Fixture.SetupAction
|
||||
{ Fixture.setupAction =
|
||||
GraphqlEngine.postMetadata_
|
||||
testEnv
|
||||
[yaml|
|
||||
type: bigquery_add_computed_field
|
||||
args:
|
||||
source: bigquery
|
||||
name: articles_no_search
|
||||
table:
|
||||
dataset: *schemaName
|
||||
name: author
|
||||
definition:
|
||||
function:
|
||||
dataset: *schemaName
|
||||
name: fetch_articles_no_user_args_returns_table
|
||||
argument_mapping:
|
||||
a_id: id
|
||||
return_table:
|
||||
name: article
|
||||
dataset: *schemaName
|
||||
|],
|
||||
Fixture.teardownAction = \_ ->
|
||||
GraphqlEngine.postMetadata_
|
||||
testEnv
|
||||
[yaml|
|
||||
type: bigquery_drop_computed_field
|
||||
args:
|
||||
source: bigquery
|
||||
name: articles_no_search
|
||||
table:
|
||||
dataset: *schemaName
|
||||
name: author
|
||||
|]
|
||||
},
|
||||
Fixture.SetupAction
|
||||
{ Fixture.setupAction =
|
||||
GraphqlEngine.postMetadata_
|
||||
@ -509,3 +567,33 @@ errors:
|
||||
message: |-
|
||||
field 'search_articles_2' not found in type: '#{schemaName}_author'
|
||||
|]
|
||||
|
||||
it "Query articles_no_search without user arguments" $ \testEnv -> do
|
||||
let schemaName = Schema.getSchemaName testEnv
|
||||
|
||||
shouldReturnYaml
|
||||
opts
|
||||
( GraphqlEngine.postGraphql
|
||||
testEnv
|
||||
[graphql|
|
||||
query {
|
||||
#{schemaName}_author(order_by: {id: asc}){
|
||||
id
|
||||
articles_no_search(order_by: {id: asc}){
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
|]
|
||||
)
|
||||
[interpolateYaml|
|
||||
data:
|
||||
#{schemaName}_author:
|
||||
- id: '1'
|
||||
articles_no_search:
|
||||
- id: '1'
|
||||
- id: '2'
|
||||
articles_no_search:
|
||||
- id: '2'
|
||||
- id: '3'
|
||||
|]
|
||||
|
Loading…
Reference in New Issue
Block a user