2

Thank you for help. I am trying to execute AND/OR operator in GraphQL without Database.

Below is Query need to execute on dataset not database. Please understand, I don't have authority to connect to any database.

    {
    customVisualsData(_filter: {and: [{expression: {field: "Country", like: "Canada"}},{expression: {field: "Profit", gt: "5000"}}]}) {
    Country
    DiscountBand
    Product
    Segment
    Profit
    }
    }

Transform dataset/JSON Object look like this.

   
    [
    
     {
    "Country": "Canada",
    "DiscountBand": "High",
    "Product": "Paseo",
    "Segment": "Government",
    "COGS": 1477815,
    "GrossSales": 2029256,
    "ManufacturingPrice": 70,
    "UnitsSold": 12230.5,
    "Profit": 300289.99999999994
     },
     {
    "Country": "United States of America",
    "DiscountBand": "High",
    "Product": "VTT",
    "Segment": "Small Business",
    "COGS": 1461250,
    "GrossSales": 1753500,
    "ManufacturingPrice": 750,
    "UnitsSold": 5845,
    "Profit": 74288
     }
    
    ]

Schema Builder, I used to create GraphQL Query builder.

var schema = buildSchema(`
        type customVisualObject {
            Country: String
            DiscountBand: String
            Product: String
            Segment: String
            COGS: Float
            GrossSales: Float
            ManufacturingPrice: Int
            UnitsSold: Float
            Profit: Float
        } 
        type Query {
            customVisualsData(_filter: FilterInput): [customVisualObject]
        }
        input FilterExpressionInput {
            field: String!
            eq: String
            gt: String
            gte: String
            like: String
        }
        input FilterInput {
            expression: FilterExpressionInput
            and: [FilterInput!]
            or: [FilterInput]
            not: [FilterInput!]
        }
`);

Please let me know, if anyone know How to set resolver for this on graphQL? Does anyone one know JSON-ata Or GraphQL library to execute such complex Query on JSON Object Not databse? I appreciate your help.

tbudhe
  • 21
  • 2

0 Answers0