i am using graphql-yoga.
# orm-help
h
i am using graphql-yoga.
r
@Hardik G 👋 Do you want to add a default value to an argument or just when returning from the resolver?
h
just returning from the resolver
r
In this case, you can simply create the resolver for that field and return a value. For e.g with Nexus, you can directly write this:
Copy code
t.field('fieldName', {
      type: 'String',
      resolve(root, _, ctx) {
        return 'default value'
      },
})
h
what is t?
type ModuleAnalytic {   name: String   group_module_name: String   views: Int   url_clicks: Int }
r
The above was an example with Nexus. If you’re not using Nexus, your resolver would look like:
Copy code
fieldName: (root, _, ctx) => {
      return 'default value'
    },
And you can return the value.
h
i want to return views and url_clicks default value 0, not null.
I have type ModuleAnalytic with four field.
i want default value for only last value.
r
Could you share your type and how you have created it?
h
Copy code
type ModuleAnalytic {
  name: String
  group_module_name: String
  views: Int
  url_clicks: Int
}
r
And the resolver?
h
Copy code
getModuleAnalytic(bot_id: String): [ModuleAnalytic]
Copy code
const Query = {
  getModuleAnalytic: async (_parent, args, { module }) => {
    try {
      // db operation
      const moduleData = await module.agreegate(pipeline);
      // moduleData = [{views: null, },{}]
      return moduleData;
    } catch (err) {
      throw Error(err);
    }
  }
}
@Ryan i have used graphql-yoga.