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 <austin@flipsidecrypto.com>
This commit is contained in:
WHYTEWYLL 2024-01-24 17:11:34 -03:00 committed by GitHub
parent a000ce04ad
commit 992947a4ea
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 169 additions and 0 deletions

View File

@ -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 %}

View File

@ -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 %}

View File

@ -0,0 +1,5 @@
-- depends_on: {{ ref('live') }}
{%- set configs = [
config_allday_udfs,
] -%}
{{- ephemeral_deploy_marketplace(configs) -}}

View File

@ -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

View File

@ -0,0 +1,5 @@
-- depends_on: {{ ref('live') }}
{%- set configs = [
config_topshot_udfs,
] -%}
{{- ephemeral_deploy_marketplace(configs) -}}

View File

@ -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

View File

@ -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 -}}.<<api_method>>
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(<url>),
{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.