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

Avoid duplicate cacheControl directives via isDirectiveDefined (redo) #2762

Merged
merged 8 commits into from Jun 25, 2019

Conversation

cheapsteak
Copy link
Member

@cheapsteak cheapsteak commented Jun 1, 2019

This is a redo of #2428 , which inadvertently broke passing in strings as typedefs and was reverted in 2.6.1

This PR adds a utility function isDirectiveDefined and uses it to guard against duplicate directives when the user's schema already contains a directive (in this case, cacheControl). It also handles when typeDefs is a string (with corresponding tests added)

@gotexis
Copy link

gotexis commented Jun 23, 2019

@cheapsteak

Anything blocking this from being merged? I seem to encounter similar problems.

Error: There can be only one type named "CacheControlScope".

Enum value "CacheControlScope.PUBLIC" can only be defined once.

Enum value "CacheControlScope.PRIVATE" can only be defined once.

There can be only one type named "Upload".
    at assertValidSDL (D:\dev\proj\fastlearn-server\server\node_modules\graphql\validation\validate.js:89:11)
    at Object.buildASTSchema (D:\dev\proj\fastlearn-server\server\node_modules\graphql\utilities\buildASTSchema.js:78:34)
    at Object.buildSchemaFromTypeDefinitions (D:\dev\proj\fastlearn-server\server\node_modules\graphql-tools\src\generate\buildSchemaFromTypeDefinitions.ts:43:32)
    at Object.makeExecutableSchema (D:\dev\proj\fastlearn-server\server\node_modules\graphql-tools\src\makeExecutableSchema.ts:52:16)
    at new ApolloServerBase (D:\dev\proj\fastlearn-server\server\node_modules\apollo-server-core\src\ApolloServer.ts:302:21)
    at new ApolloServer (D:\dev\proj\fastlearn-server\server\node_modules\apollo-server-express\src\ApolloServer.ts:84:5)
    at Object.<anonymous> (D:\dev\proj\fastlearn-server\server\src\app.ts:54:16)
    at Module._compile (internal/modules/cjs/loader.js:734:30)
    at Module._compile (D:\dev\proj\fastlearn-server\server\node_modules\source-map-support\source-map-support.js:521:25)
    at Module.m._compile (C:\Users\e\AppData\Local\Temp\ts-node-dev-hook-9660947657511609.js:56:25)
[ERROR] 14:43:08 Error: There can be only one type named "CacheControlScope".

Enum value "CacheControlScope.PUBLIC" can only be defined once.

Enum value "CacheControlScope.PRIVATE" can only be defined once.

There can be only one type named "Upload".

Is this related to this commit?

@cheapsteak cheapsteak force-pushed the chang/avoid-duplicate-directives-redo branch from 0949bd4 to ed38ef7 Compare June 24, 2019 13:24
@cheapsteak cheapsteak requested a review from abernix June 24, 2019 13:24
@cheapsteak
Copy link
Member Author

@gotexis it should help (as long as there otherwise only exists one declaration of the CacheControlScope enum in your schema)

@abernix abernix merged commit 65ca915 into master Jun 25, 2019
@abernix abernix deleted the chang/avoid-duplicate-directives-redo branch June 25, 2019 16:41
@abernix abernix added this to the Release 2.6.6 milestone Jun 25, 2019
abernix added a commit to mrsunboss/apollo-server that referenced this pull request Jun 26, 2019
…eality.

While no TypeScript user would have ever been able to use it as such, Apollo
Server has for a long time (as a side-effect of its past reliance on
`graphql-tools`) accepted string types (and arrays of string types) for
`typeDefs`.

This hasn't been reflected in the TypeScript types, and has thus made it
possible to sandbag non-TypeScript users (which let's remind ourselves, is
still the majority) who were strings, when new code — like that in apollographql#2762 —
didn't defend against what TypeScript indicated would be fine.

Even if we don't necessarily support string types as a common pattern
anymore, they still work, and we need to make sure we're coding for what we
expect to work until the time comes to make a breaking change.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants