0

I am trying to create a graphQL query in which i want to check if the variable by the name $Month is equal to the string "March". But i cant find a way to do it.

query MyQuery($userid : ID , $Month : String) {
  dbo_table(where: 
    { 
      userid: { _eq: $userid },
  
      _or : [ 
              { MonthCreated: { _eq : $Folder }},
              {  $Month  : { _eq : "March" }
            ]
    }
  )
    {  $Month  : { _eq : "March" }

The above approach is giving me a syntax error.

Nirmal
  • 1
  • 2

1 Answers1

1

In graphql you can send the needed variable to query handler and build your query using apollo, just like this...

query get_users_by_role ($role: String!){
  user(where: {role: {_eq: $role}}) {
    id
    username
  }
}

In the above example, I build a query for getting a list of users with the role name is matched with role variable that i will sent.

I send the query using applo as follows,

this.$apollo.query({
  query: gql`
    query get_users_by_role($role: String!) {
      user(where: { role: { _eq: $role } }) {
        id
        username
      }
    }
  `,
  variables: {
    role: "Admin",
  },
});

Ask me if you need further explanation.

Endriyas
  • 546
  • 6
  • 13