GraphQL query returns all by default if parameter is null

Viewed 217

I have a simple question, I'm currently using GraphQL/Hasura to subscribe to some data, this subscription takes an id as parameter but in the case where the id is null my subcription returns all the data by default...

Here is the subscription :

subscription MySubscription($id: Int) {
  dcim_device(where: { virtual_chassis_id: { _eq: $id } }) {
    id
    name
    serial
    site_id
    status
    ip_address {
      address
    }
    dcim_platform {
      name
    }
    device_tags {
      tag_id
      extras_tag {
        id
        name
        color
      }
    }
    dcim_devicerole {
      color
      name
    }
    virtual_chassis_id
    dcim_virtualchassis {
      id
    }
    dcim_interfaces {
      enabled
      name
      id
      type
    }
  }
}

And here is the Vue.js front-end part in which I call my subscription with Apollo :

apollo: {
    $subscribe: {
      dcim_device: {
        query: require("../../graphql/subscribeToNewDevicesByVCid.gql"),
        variables() {
          return {
            id: this.node.dcim_virtualchassis.id,
          };
        },
        result({ data }) {
          this.devices = data.dcim_device;
          console.log(this.devices);
        },
      },
    },
  },

As you can see "node" can change based on user click and there are in my case some nodes that have null virtual_chassis_id...

I would like to know if it's possible to catch or something like that the case where no parameters are given to the query in order to display something else.

Thanks in advance !

0 Answers
Related