From 204eaa2a1142d08a9376e186fdb9ea1e8b48507d Mon Sep 17 00:00:00 2001 From: Jason Date: Mon, 26 Dec 2022 14:35:00 +0200 Subject: [PATCH] filter out derived fields (since they can cause bugs in subgraphs if left in) --- package/package.json | 2 +- package/src/Index.bs.js | 9 ++++++++- package/src/Index.res | 14 +++++++++++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/package/package.json b/package/package.json index 36c5bc8..b7445b7 100644 --- a/package/package.json +++ b/package/package.json @@ -1,6 +1,6 @@ { "name": "@float-capital/float-subgraph-uncrashable", - "version": "0.0.0-alpha.6", + "version": "0.0.0-internal-testing.2", "description": "Safe Subgraph Code Generation Framework by Float", "main": "index.js", "repository": "https://github.com/Float-Capital/float-subgraph-uncrashable", diff --git a/package/src/Index.bs.js b/package/src/Index.bs.js index f8b38a0..cba0873 100644 --- a/package/src/Index.bs.js +++ b/package/src/Index.bs.js @@ -245,7 +245,14 @@ function run(entityDefinitions, codegenConfigPath, outputFilePath) { var fieldsMap = {}; Belt_Array.map(fields, (function (field) { var fieldName = field.name.value; - fieldsMap[fieldName] = field; + var isDerivedFromField = Belt_Array.keep(field.directives, (function (directive) { + return directive.name.value === "derivedFrom"; + })).length !== 0; + if (!isDerivedFromField) { + fieldsMap[fieldName] = field; + return ; + } + })); var entityConfig = Belt_Option.getWithDefault(Js_dict.get(uncrashableConfig.entitySettings, name), { useDefault: {}, diff --git a/package/src/Index.res b/package/src/Index.res index d6200c2..4c34f8f 100644 --- a/package/src/Index.res +++ b/package/src/Index.res @@ -234,7 +234,19 @@ let run = (~entityDefinitions, ~codegenConfigPath, ~outputFilePath) => { let fieldsMap = Js.Dict.empty() let _ = fields->Array.map(field => { let fieldName = field["name"]["value"] - fieldsMap->Js.Dict.set(fieldName, field) + let isDerivedFromField = + field["directives"] + ->Array.keep( + directive => { + directive["name"]["value"] == "derivedFrom" + }, + ) + ->Array.length > 0 + + // NOTE: currently we completely ignore derived fields + if !isDerivedFromField { + fieldsMap->Js.Dict.set(fieldName, field) + } }) let entityConfig = uncrashableConfig["entitySettings"]