-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Open
Labels
Description
Issue
When we are tracking a table, Hasura checks for conflicting nodes by running the following introspection query:
{
__schema {
queryType {
fields {
name
}
}
}
}
And checks if the "table name" which is going to be tracked already exists or not. This is alright unless the source is having any source customization associated with it. There are two possible ways to trick this behaviour:
- Track a table, say prefix_foo and then add another source with root_fields.prefix set to prefix_. Now try adding a table foo to the new source and track it. Ideally this should have been caught by the checkConflictingNode, but it doesn't. This gets caught in the later step.
- Track a table say, foo and add another source with root_fields.prefix set to say prefix_, now try adding a table called foo in the new source. This should be allowed as the names don't conflict, but the checkConflictingNode will raise an error.
Possible solution
Create a function which can generate the root field names based on the source customization and the new table name which needs to be tracked (following the naming convention set). Please note that this should return the namespace if the source customization have any.
getRootFieldNames :: SourceCustomization -> Text -> [Text]
getRootFieldNames sCustomization tableName = undefined
Then run the checkConflictingNode with these names.
trackExistingTableOrViewP2 ::
forall b m.
(MonadError QErr m, CacheRWM m, MetadataM m, BackendMetadata b) =>
SourceName ->
TableName b ->
Bool ->
TableConfig b ->
m EncJSON
trackExistingTableOrViewP2 source tableName isEnum config = do
sc <- askSchemaCache
sourceCustomization <- (fmap (\e -> AB.dispatchAnyBackend @Backend e _smCustomization) . OMap.lookup source . _metaSources) <$> getMetadata
let
fieldNames = getRootFieldNames sourceCustomization tableName
{-
The next line does more than what it says on the tin. Removing the following ...
-}
forM_ fieldNames (checkConflictingNode sc) -- checkConflictingNode sc $ snakeCaseTableName @b tableName
...