From 992947a4eaa8fccdf2cfcd2cb73a470ff5e89fa2 Mon Sep 17 00:00:00 2001 From: WHYTEWYLL <49686519+WHYTEWYLL@users.noreply.github.com> Date: Wed, 24 Jan 2024 17:11:34 -0300 Subject: [PATCH] An 4358 flow live query wrapper graph ql endpoint s (#82) * add: allday * add: allday * fix: config * fixes * readme * topshot, and rename * fix: set to user-agent * rename udfs --------- Co-authored-by: Austin --- macros/marketplace/allday/allday.graphql.sql | 23 ++++++++ .../marketplace/topshot/topshot.graphql.sql | 23 ++++++++ models/deploy/marketplace/allday/allday__.sql | 5 ++ models/deploy/marketplace/allday/allday__.yml | 35 ++++++++++++ .../deploy/marketplace/topshot/topshot__.sql | 5 ++ .../deploy/marketplace/topshot/topshot__.yml | 23 ++++++++ .../integration/__overview__.md | 55 +++++++++++++++++++ 7 files changed, 169 insertions(+) create mode 100644 macros/marketplace/allday/allday.graphql.sql create mode 100644 macros/marketplace/topshot/topshot.graphql.sql create mode 100644 models/deploy/marketplace/allday/allday__.sql create mode 100644 models/deploy/marketplace/allday/allday__.yml create mode 100644 models/deploy/marketplace/topshot/topshot__.sql create mode 100644 models/deploy/marketplace/topshot/topshot__.yml create mode 100644 models/doc_descriptions/integration/__overview__.md diff --git a/macros/marketplace/allday/allday.graphql.sql b/macros/marketplace/allday/allday.graphql.sql new file mode 100644 index 0000000..7c71ade --- /dev/null +++ b/macros/marketplace/allday/allday.graphql.sql @@ -0,0 +1,23 @@ +{% macro config_allday_udfs(schema_name = "allday", utils_schema_name = "allday_utils") -%} +{# + This macro is used to generate the AllDay calls + #} + +- name: {{ schema_name -}}.graphql + signature: + - [QUERY, OBJECT, The GraphQL query] + return_type: + - "VARIANT" + options: | + COMMENT = $$Run a graphql query on AllDay.$$ + sql: | + SELECT + live.udf_api( + 'GET', + CONCAT('https://nflallday.com/consumer/graphql?query=', utils.udf_object_to_url_query_string(QUERY)), + {'User-Agent': 'Flipside_Flow_metadata/0.1','Accept-Encoding': 'gzip', 'Content-Type': 'application/json', 'Accept': 'application/json','Connection': 'keep-alive'}, + {}, + '_FSC_SYS/ALLDAY' + ) as response + +{% endmacro %} \ No newline at end of file diff --git a/macros/marketplace/topshot/topshot.graphql.sql b/macros/marketplace/topshot/topshot.graphql.sql new file mode 100644 index 0000000..8ee7da3 --- /dev/null +++ b/macros/marketplace/topshot/topshot.graphql.sql @@ -0,0 +1,23 @@ +{% macro config_topshot_udfs(schema_name = "topshot", utils_schema_name = "topshot_utils") -%} +{# + This macro is used to generate the Topshot calls + #} + +- name: {{ schema_name -}}.graphql + signature: + - [QUERY, OBJECT, The GraphQL query] + return_type: + - "VARIANT" + options: | + COMMENT = $$Run a graphql query on TopShot.$$ + sql: | + SELECT + live.udf_api( + 'POST', + 'https://public-api.nbatopshot.com/graphql', + {'User-Agent': 'Flipside_Flow_metadata/0.1','Accept-Encoding': 'gzip', 'Content-Type': 'application/json', 'Accept': 'application/json','Connection': 'keep-alive'}, + QUERY, + '_FSC_SYS/TOPSHOT' + ) as response + +{% endmacro %} \ No newline at end of file diff --git a/models/deploy/marketplace/allday/allday__.sql b/models/deploy/marketplace/allday/allday__.sql new file mode 100644 index 0000000..d1879d0 --- /dev/null +++ b/models/deploy/marketplace/allday/allday__.sql @@ -0,0 +1,5 @@ +-- depends_on: {{ ref('live') }} +{%- set configs = [ + config_allday_udfs, + ] -%} +{{- ephemeral_deploy_marketplace(configs) -}} \ No newline at end of file diff --git a/models/deploy/marketplace/allday/allday__.yml b/models/deploy/marketplace/allday/allday__.yml new file mode 100644 index 0000000..3f3fe9d --- /dev/null +++ b/models/deploy/marketplace/allday/allday__.yml @@ -0,0 +1,35 @@ +version: 2 +models: + - name: allday__ + columns: + - name: graphql + tests: + - test_udf: + name: test_allday__graphql_status_200 + args: > + { + 'query': '{ + searchPlays(input: {filters: {byFlowIDs: ["1666"]}}){ + plays { + id + flowID + metadata { + description + playerID + playTypeV2 + classification + week + season + playerFullName + playerPosition + playerDraftTeam + gameDate + teamName + } + } + }', + 'variables': '{}' + } + assertions: + - result:status_code = 200 + - result:error IS NULL diff --git a/models/deploy/marketplace/topshot/topshot__.sql b/models/deploy/marketplace/topshot/topshot__.sql new file mode 100644 index 0000000..a1a6533 --- /dev/null +++ b/models/deploy/marketplace/topshot/topshot__.sql @@ -0,0 +1,5 @@ +-- depends_on: {{ ref('live') }} +{%- set configs = [ + config_topshot_udfs, + ] -%} +{{- ephemeral_deploy_marketplace(configs) -}} \ No newline at end of file diff --git a/models/deploy/marketplace/topshot/topshot__.yml b/models/deploy/marketplace/topshot/topshot__.yml new file mode 100644 index 0000000..1b0c340 --- /dev/null +++ b/models/deploy/marketplace/topshot/topshot__.yml @@ -0,0 +1,23 @@ +version: 2 +models: + - name: topshot__ + columns: + - name: graphql + tests: + - test_udf: + name: test_topshot__graphql_status_200 + args: > + { + 'query': ' + query { + getMintedMoment (momentId: 5) { + data { + id + } + } + } + }', + 'variables': '{}' + } + assertions: + - result:status_code = 200 diff --git a/models/doc_descriptions/integration/__overview__.md b/models/doc_descriptions/integration/__overview__.md new file mode 100644 index 0000000..9c0c0a1 --- /dev/null +++ b/models/doc_descriptions/integration/__overview__.md @@ -0,0 +1,55 @@ +# Flipside Crypto LiveQuery Models Integration Guide + +Welcome to the comprehensive guide for integrating new models into Flipside Crypto's LiveQuery system! + +## **Guide Overview** + +This guide is designed to walk you through the process of integrating a new model into LiveQuery. It covers essential steps and provides helpful tips for a smooth integration. + +### Integration Steps + +#### 1. Model and Test Creation + +Navigate to `models/deploy/marketplace/` and create a new folder named after your API. In this folder, you should create two essential files: + +- `NAME-OF-YOUR-MODEL__.sql` - This file will contain your model code. +- `NAME-OF-YOUR-MODEL__.yml` - This file is for your model tests. + +**Tip:** For guidance, refer to other models in the `models/deploy/marketplace` directory. + +#### 2. Macro Creation + +Within the same directory (`models/deploy/marketplace/`), create a new folder for your API and add the following file: + +- `udfs.yaml.sql` - This file is where you'll define the macro that your model will execute. Structure it as follows: + + ```yaml + - name: {{ schema_name -}}.<> + signature: + - [QUERY, OBJECT, The GraphQL query] + return_type: + - "VARIANT" + options: | + COMMENT = $$Your comment$$ + sql: | + SELECT + live.udf_api( + 'GET', + udf_object_to_url_query_string(), + {headers}, + {}, + '_FSC_SYS/SCHEMA_NAME' + ) as response + ``` + +#### 3. Deployment + +Deploy your model following the standard deployment procedures. + +- `dbt run -s models/deploy/marketplace/your_model/your_model__.sql -t dev --vars '{"UPDATE_UDFS_AND_SPS":True}'` + +- `dbt test -s models/deploy/marketplace/your_model/your_model__.sql -t dev --vars '{"UPDATE_UDFS_AND_SPS":True}'` + +#### Additional Tips: + +- Ensure successful model runs. In case of errors, always refer to the log files for troubleshooting.