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

[question] How do I use references in GraphQLType::Context? #105

Closed
idubrov opened this issue Nov 8, 2017 · 3 comments
Closed

[question] How do I use references in GraphQLType::Context? #105

idubrov opened this issue Nov 8, 2017 · 3 comments
Labels
duplicate This issue or pull request already exists support

Comments

@idubrov
Copy link
Contributor

idubrov commented Nov 8, 2017

I want to pass multiple references as a context for the query execution.

If I only have one Database struct, then I can make Context = Database and all API is designed in a way that it would accept a reference.

However, what if I have two databases? Context = (Database1, Database2) will not work as I don't have them in one tuple and I cannot move them.

Context = (&Database1, &Database2) doesn't work because of lifetimes, as it seems like there is no way to link lifetime of these references to the lifetime of the request.execute.

I also tried to use trait as a Context (since only a reference is passed around, it should be possible to have support for these), so reference to context becomes trait object (and I can hide stuff in the concrete implementation), but compiler would require that Context is Sized (which I tried to relax by specifying CtxT to be ?Sized everywhere, but it didn't work, don't remember why, though...).

Any advice here?

I also have similar problem with TypeInfo. I have a repository of types and I want to have a reference to it inside each concrete TypeInfo I'm having. As an option, I can build a completely self-sustained TypeInfo's, but I would prefer to have them small and shallow and reference this global type registry for more meta-info for types.

Is there a way to do it better (currently I just use unsafe pointers as a temporary remedy...)?

@idubrov idubrov closed this as completed Apr 17, 2018
@miracle2k
Copy link

Did you ever find an answer?

@idubrov
Copy link
Contributor Author

idubrov commented May 17, 2018

No, not really. I think, we ended up having a single item.

Today I would probably use Arc if needed.

@theduke theduke added duplicate This issue or pull request already exists support labels May 21, 2019
@theduke
Copy link
Member

theduke commented May 21, 2019

As a late heads up, this is explained in #143 , together with a solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists support
Projects
None yet
Development

No branches or pull requests

3 participants