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

directives as tuple? #31

Closed
rinnierin opened this issue May 10, 2019 · 2 comments
Closed

directives as tuple? #31

rinnierin opened this issue May 10, 2019 · 2 comments

Comments

@rinnierin
Copy link

rinnierin commented May 10, 2019

https://github.com/graphql-python/graphql-core-next/blob/b0fa058bacf3913d0af9a75289e241f343c3842a/graphql/type/directives.py#L169

Hi, I'm new to GraphQL and have a quick question. I want to add a custom directive to the default directives including skip and included.

schema = GraphQLSchema(query, directives=specified_directives + [custom_directives])

However, the following TypeError occurs:
can only concatenate tuple (not "list") to tuple

I noticed that graph-core returns a list of these predefined directives, but graph-core-next returns a tuple. Is there a reason for this?

@Cito
Copy link
Member

Cito commented May 12, 2019

In GraphQL.js which we want to replicate it has the type ReadOnlyArray. Tuples are immutable and therefore a good fit in Python. The intention is that this list should not be accidentally mutated.

Maybe using a subclass of list that is immutable would be better. I'm thinking about it.

Meanwhile, you can pass the directives to the schema as list(specified_directives) + [custom_directives] or as specified_directives + tuple(custom_directives) or as [*specified_directives, *custom_directives].

@Cito
Copy link
Member

Cito commented May 16, 2019

Made it a list that cannot be modified now (and you can even add a tuple to that list if you want).

@Cito Cito closed this as completed May 16, 2019
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

No branches or pull requests

2 participants