Skip to content

Conversation

sourabh1007
Copy link
Contributor

Why make this change?

As mentioned here #887, if entity is not configured in DAB Config JSON file, it throws a generic exception i.e. keyNotFoundException.

As part of this PR, changed this message to make it clearer.

What is this change?

If Entity is not configured then DAB will throw System.ApplicationException with error message as "The entity '' was not found in the dab-config json"

How was this tested?

  • Integration Tests
  • Unit Tests

Sample Request(s)

  • Example REST and/or GraphQL request to demonstrate modifications
  • Example of CLI usage to demonstrate modifications

@sourabh1007 sourabh1007 enabled auto-merge (squash) April 24, 2024 10:19
@sourabh1007
Copy link
Contributor Author

/azp run

Copy link
Member

@sajeetharan sajeetharan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@sourabh1007
Copy link
Contributor Author

/azp run

@sourabh1007 sourabh1007 merged commit e5cc8de into main Apr 25, 2024
@sourabh1007 sourabh1007 deleted the users/sourabhjain/keynotfounderrormessage branch April 25, 2024 15:40
}
else
{
throw new ApplicationException($"The entity '{key}' was not found in the dab-config json");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why ApplicationException and not DataApiBuilderException which is used throughout the project?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes sense, Since, it is a small change, making this change in patch PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sajeetharan what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also message should be something like:
"... was not found in the runtime config."

using "dab-config json" is too close to "dab-config.json" which is an explicit file name. End-users most likely aren't using dab-config.json as the file name (more likely dab-config.mssql.json, dab-config.cosmos.json etc.) so this may add confusion.

Comment on lines +2974 to +2994
using (TestServer server = new(Program.CreateWebHostBuilder(args)))
using (HttpClient client = server.CreateClient())
{
string query = @"{
EntityName {
items{
id
title
}
}
}";

object payload = new { query };

HttpRequestMessage graphQLRequest = new(HttpMethod.Post, "/graphql")
{
Content = JsonContent.Create(payload)
};

ApplicationException ex = await Assert.ThrowsExceptionAsync<ApplicationException>(async () => await client.SendAsync(graphQLRequest));
Assert.AreEqual(ex.Message, "The entity 'Planet' was not found in the dab-config json");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this test sending a GraphQL request? if the entity doesn't exist in the config, shouldn't there be a startup error?

Alternatively, if the intent is to capture some sort of error that occurs during runtime, then erroring on a non-existent entity should be handled by HotChocolate which detects that the requested entity is not part of the GraphQL schema -> HTTP400 bad request/GraphQL error because request doesn't adhere to schema.

Copy link
Contributor Author

@sourabh1007 sourabh1007 Apr 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not schema error, it is config error, if there is an entity which is defined in schema but not defined in config then, Hotchocolate wouldn't even know about it since schema has this information. It will fail when DAB check for the entity in the config. Hence, failed during the operation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add more details to the test description then? there's no context in the test describing what mismatch exists between schema.gql and dab-config.json. The request is querying "EntityName", but the error message says "Planet". That's not really actionable by the end user because it's not immediately clear what the relation is (or isn't) between "EntityName" and "Planet"

@seantleonard
Copy link
Contributor

PR description nor the linked issue describe where this issue was surfacing: as a response to a request, or during DAB startup. Please include a before/after request that shows how your fix appears to the end user.

sourabh1007 added a commit that referenced this pull request Jun 21, 2024
… runtime config (#2272)

## Why make this change?

Customers are getting` System.Collections.Generic.KeyNotFoundException`
when there configuration is missing for an entity defined in schema
file.

## What is this change?
As part of this PR, throwing proper message saying, entity is not
present in runtimeconfig.

Similar changes were made at this PR also
#2186
## How was this tested?

- [ ] Integration Tests
- [ ] Unit Tests

Closes #2266 #887

---------

Co-authored-by: Sean Leonard <sean.leonard@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants