【问题标题】:Writing junction for multiple joins using join-monster-graphql-tools-adapter in graphql and join-monster在 graphql 和 join-monster 中使用 join-monster-graphql-tools-adapter 为多个连接编写联结
【发布时间】:2021-05-06 18:58:00
【问题描述】:

我一直在尝试编写联结,我正在使用 join-monster-graphql-tools-adapter。这是示例代码

assets:{
          junction: {
            sqlTable: 'FPAS',
          sqlJoins: [(contractTable, junctionTabel) => `${contractTable}.CONTRACT_ID =${junctionTabel}.CONTRACT_ID`,
                     (junctionTabel,assetTable) => `${junctionTabel}.ASSET_ID = ${assetTable}.ASSET_ID`]
        }

但在测试时失败并显示错误消息:Cannot read property 'sqlTable' of undefined

谁能帮我解决这个问题。

【问题讨论】:

    标签: graphql apollo-server


    【解决方案1】:

    好的,经过短暂的挣扎后,我发现了问题所在。这是一个放错位置的支架。因此,我可以得出结论,join-monster-graphql-tools-adapter 中的联结正在工作。 下面是 joinMonsterAdapt 的示例。

    joinMonsterAdapt(schema, {
      Query: {
        fields: {
          // add a function to generate the "where condition"
          contract: {
            where: (table, args) => `${table}.CODE LIKE '%${args.code}'`
          }
        }
      },
    Contract: {
        sqlTable: 'DataLakeCMS.CONTRACT',
        uniqueKey: 'CONTRACT_ID',
        fields: {
          contractId: {
            sqlColumn: 'CONTRACT_ID'
          },
          assets: {
            junction: {
              sqlTable: 'Con_Pas',
              uniqueKey: 'PrimaryKey',
              sqlJoins: [
                // first the parent table to the junction
                (contractTable, junctionTable, args) =>
                  `${contractTable}.ID = ${junctionTable}.ID`,
                // then the junction to the child
                (junctionTable, assetTable, args) =>
                  `${junctionTable}.ID = ${assetTable}.ID`
              ]
            }
          }
        }
      }
    })
    

    【讨论】:

      猜你喜欢
      • 2020-07-07
      • 2017-08-17
      • 2017-11-04
      • 2019-05-29
      • 2019-08-06
      • 2021-03-01
      • 1970-01-01
      • 2019-07-14
      • 2016-07-16
      相关资源
      最近更新 更多