Please confirm @default operation

I’m using the js gprc client.

type GroupChatDirectMessageTab {
  sticky: Boolean! @default(add: { value: "true" }) @search
  pos: Int! @default(add: { value: "0" })

I’m omitting the above fields as they should be added per their respective defaults.

const nQuad = `
  _:dm <GroupChatDirectMessageTab.xid> "${id}" .
  _:dm <GroupChatDirectMessageTab.uniqId> "${data.uniqId}" .
  _:dm <GroupChatDirectMessageTab.chatUser> uid(fromUser) .
  _:dm <dgraph.type> "GroupChatDirectMessageTab" .
  uid(fromUser) <GroupChatUser.dmTab> _:dm .
`;

When I query:

"message": "Non-nullable field 'sticky' (type Boolean!) was not present in result from Dgraph.  GraphQL error propagation triggered.",

Please let me know what I’m doing wrong here.

Thanks

dgraph has not default value. and sticky is null for you.

I know sticky is null.

I’m not using the cloud, I’m using standalone.

Therefore default is available.

default is handled only by the /graphql endpoint in the API logic. Just like the inverse edges. So if you are inserting data with DQL, behind your GraphQL API, then any defaults are ignored.

Defaults are set on the inputs and not the outputs. Maybe this should be the feature request:

Make defaults also work for outputs to prevent GraphQL required fields errors. This would store nothing in the database, but when it is missing from the output, would default to the desired output. This would look weird with Datetime, but something like this would work, But when I say, “would work” it would not allow you to filter by this value, only see this default value if the default was only in the output and not the input.

2 Likes

@amaster507 thanks for the reply.

So chalk this up to the graphql and dql confusion. Still working it out…

1 Like