Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Schema name conflict errors #2589

Merged
merged 10 commits into from Oct 21, 2022
Merged

fix: Schema name conflict errors #2589

merged 10 commits into from Oct 21, 2022

Conversation

calvincestari
Copy link
Member

@calvincestari calvincestari commented Oct 18, 2022

PR 2 of 3 for #2546

This PR ensures that the user-given schema name:

  • does not conflict with any of the generated file/type names by disallowing the schema name to match any of the schema referenced types
  • does not conflict with any of the generation selection set names by disallowing a schema name matching any entity field name and any pluralized version of an entity list name
  • these checks are done during the compilation stage because that is where the code still has access to the schema and can check field definition types
  • ValidationRule checks have been reduced to only reserved words

@netlify
Copy link

netlify bot commented Oct 18, 2022

Deploy Preview for apollo-ios-docs canceled.

Name Link
🔨 Latest commit 5ddb9a0
🔍 Latest deploy log https://app.netlify.com/sites/apollo-ios-docs/deploys/635321c3fee35e000846b642

@AnthonyMDev
Copy link
Contributor

AnthonyMDev commented Oct 18, 2022

Just a typo and minor addition to the schema conflict error message. But otherwise this LGTM!

@calvincestari
Copy link
Member Author

Just a type and minor addition to the schema conflict error message. But otherwise this LGTM!

Still wanting to add the entity vs. list behaviours to this PR too.

if (isListType(fieldType) || (isNonNullType(fieldType) && isListType(fieldType.ofType))) {
validateFieldName(selectionNode, validationOptions.disallowedEntityListFieldNames)
} else if (isCompositeType(unwrappedFieldType)) {
validateFieldName(selectionNode, validationOptions.disallowedEntityFieldNames)
Copy link
Member Author

Choose a reason for hiding this comment

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

Arguably this check could go into the below if (isCompositeType(unwrappedFieldType)) { statement, let me know if you feel strongly about it. I prefer to have the if else and keep the logic together.

Copy link
Member Author

Choose a reason for hiding this comment

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

Also, if we move the check into the if statement below then the validation will be done twice because a field can be both a list type and and a composite type.

}
}

func test__validateDocument__givenFieldNameIsSchemaName_throwsError() throws {
Copy link
Member Author

Choose a reason for hiding this comment

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

This test now becomes part of the compilation stage tests.

@calvincestari calvincestari marked this pull request as ready for review October 21, 2022 17:07
@calvincestari
Copy link
Member Author

@AnthonyMDev this PR now has the entity and list disallow logic. I still need make the change to condense the ValidationOptions into a sub struct but the rest is ready for another pass.

Copy link
Contributor

@AnthonyMDev AnthonyMDev left a comment

Choose a reason for hiding this comment

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

Thanks so much @calvincestari, I know this one was a lot harder than we expected!

Sources/ApolloCodegenLib/Frontend/ValidationOptions.swift Outdated Show resolved Hide resolved
@calvincestari calvincestari merged commit 14075d5 into main Oct 21, 2022
@calvincestari calvincestari deleted the fix/schema-name-conflict branch October 21, 2022 22:56
This was referenced Oct 21, 2022
@calvincestari calvincestari linked an issue Oct 24, 2022 that may be closed by this pull request
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.

Problem with schemaName
2 participants