-
Notifications
You must be signed in to change notification settings - Fork 56
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
"Import specific types" works as "Import all types" #235
Comments
It happens to me too |
I'm experiencing the same thing but the problem is made much more apparent when trying to use graphqlgen. Let's say I have 3 types in my prisma schema and I only want to expose (and write resolvers for) 2 of them in my public API. That is currently not possible with this bug. Grapqlgen is receiving every type from |
Any fix/work around to this? |
@ellipticaldoor : Can you provide a minimal reproduction? Import specific types would also import the types that are used by that type (like inputs for its where etc). I will take a look at this today. |
I'm not sure how much of a reproduction you want (github repo?), but the following Problem# import Node from './generated/prisma.graphql'
type Query {
profile: UserProfile
}
type UserProfile implements Node {
id: ID!
name: String!
role: Role!
posts: [Post!]!
location: Location!
} What happens?It imports more than expected. I didn't declare or imported the types What is expected?
|
@Elfayer : Thanks for the details, Github repo would be the best (if you have the time).. maybe a repo that just prints the discrepancy using If there is no Github repo, I will try to create one and validate/fix this soon anyways. |
@divyenduz Reproduction here: https://codesandbox.io/s/k9w3wx4k1r |
@Elfayer : It is indeed importing only types that are used, albeit "magically" since they are not explicitly imported. However, it is not importing everything. Like in this case: https://codesandbox.io/s/0xj69o9qmw I added an unused enum to |
@divyenduz Are you saying it is a normal behavior? I do not expect that behavior from a "specific" import. Also, if you try to replace |
@Elfayer : No, I am not stating that this is normal behavior, I just noticed that the bug (or feature) is different from original specification. Your last comment also points out some confusion regarding collisions and also points out that specific import does not work at all. Maybe these are three separate issues. To my understanding @maticzav will pick this up sometime soon and help us navigate through it 🙂 Thanks for reporting it with all the details and the reproductions, helps a lot 🙌 |
Happy to help 😉 |
I have a User type in the DB and another User type (with less fields) in the API. I'm not importing User from the DB. However, in the server playground the type I see is the one from the DB. The one from the API only works if I change its name. I guess it's being overridden by the one in the DB because of this "import all" issue? I'm only doing |
Hey Prisma team, it'd be nice if somebody look into this issue since Oct 2018. Because I'm doing selective import, but instead I'm getting everything. |
Experiencing the same issues as above and it makes it very difficult to reuse anything from a generated prisma schema without exposing far too much in your API. Would really appreciate if someone from the Prisma team could look into fixing this soon. |
If it's not going to be fixed I think will be good to at least mention it on the Readme, just to avoid surprises |
Hey @ellipticaldoor 👋, Could you check out the reproduction test that I made here? I tried to follow the CodeSandbox reproductions above but I cannot reproduce the failing behaviour. https://github.com/prisma/graphql-import/blob/import-specific-fix/fixtures/specific/a.graphql |
@maticzav hey, thanks for your response. Maybe this gist will help clarify the issue that I and others are seeing: https://gist.github.com/amille14/b063f5cabfd4838c27bec5abe83ee544 In my example, importing only The reason you are unable to repro the issue in your tests is because the |
Hey @amille14, thank you for the follow-up! After commenting, I figured out how to reproduce it myself as well. You can already see new test cases and code changes in the above branch. Interestingly, I discovered that such functionality isn't a bug in the current code but a feature. I believe @schickling and @kbrandwijk must have thought that would come in handy. |
Awesome! Appreciate you taking a look at this as it has been preventing me from reusing pieces of my generated Prisma schema in my API (due to security concerns, exposing too much info about the database), resulting in a ton of extra work on the API layer. I could see the current behavior being useful as an import option, but at least in my case it was not the expected default behavior. Thank you, hope this fix gets merged soon! |
Hey @schickling @timsuchanek @amille14 @ellipticaldoor 👋, Let me first give a brief overview of how From the reproduction cases published above, I was able to figure the pattern which, as mentioned, is not an issue but rather a feature turned issue. (Very Facebook-ish.) Anyhow, currently I believe this is a very nice feature and wouldn't call it an issue at all. As an example compare the two schemas below. # import B from "b.graphql"
type A {
first: String
second: Float
b: B
}
# import B, C from "b.graphql"
type A {
first: String
second: Float
b: B
} The first one is, in my opinion, far cleaner than the second one. What's I think it would make sense to take a step backwards here and rethink the intention of |
@maticzav Thanks for debugging this. About this "hidden" feature, it was mentioned in other issue if I don't remember wrong, and I personally think it's fine. However, I think there's another related issue since I've seen leaked types that were not a dependency of other types. I believe it was due to nested imports (not sure if they are supported): A-file imports some types from B-file, B-file imports some types from C-file. As a result, all types from C-file were leaking and overwriting other types. Perhaps this is what happened to others. |
OK! @maticzav after reading your last comment I went back and took another look at this and ran some test cases. I think I figured out what's causing all the confusion, at least on my end. I have some examples that will hopefully clarify all of this for everyone. This post might get a little long so bare with me. The problem seems to stem from the fact that importing a single specific type does not import that type, it only imports its dependencies. Example 1:
type A {
something: String
}
# import A from './a.graphql' Expected output from type A {
something: String
} Actual output from Yes, the output is empty. Example 2:
type A {
something: String
b: B
}
type B {
something: String
}
# import A from './a.graphql' Expected output from type A {
something: String
b: B
}
type B {
something: String
} Actual output from type B {
something: String
} Only the dependencies (B) are imported, not the specified type (A). Now, this really starts causing problems when you have types in different files that have the same name as the specific type you are trying to import (but which does not actually get imported, as seen in the example above). For some reason, the type with a matching name from a different file will get pulled in instead of the one from the file you wanted. Example 3:
type A {
b: B
correct: String
}
type B {
c: C
incorrect: String
}
type C {
incorrect: String
}
type B {
a: A
c: C
correct: String
}
type C {
correct: String
}
type A {
incorrect: String
}
# import A from './a.graphql'
# import B from './b.graphql'
# import C from './c.graphql' Expected output from type A {
b: B
correct: String
}
type B {
a: A
c: C
correct: String
}
type C {
correct: String
} Actual output from type B {
a: A
c: C
correct: String
}
type A {
incorrect: String
}
type C {
correct: String
} Notice that the incorrect type A is imported in the final schema. This is definitely a bug, not a "feature" in my book. Otherwise, I think the general behavior of automagically pulling in dependencies is ok, as long as it pulls in the correct dependencies. It's possible that just fixing examples 1 and 2 will also fix example 3. |
hey! tomorrow I can check it! |
@ryanquinn3 could you provide a reproduction to the issue you are experiencing? I am not sure I understand your problem. Isn't |
Hey @amille14 👋, Thank you for providing such a great overlook of the issue. I am having difficulties reproducing your results. Could you provide a reproduction repository for your cases? What's particularly interesting to me is that there are test cases with almost exactly the same inputs as you provided but resolve in different outcomes. Example 1https://github.com/prisma/graphql-import/blob/master/fixtures/imports-only/all.graphql Example 2https://github.com/prisma/graphql-import/tree/master/fixtures/field-types Example 3Example 3 occurs due to an unordered definition pool. All in all, I believe this issue isn't as trivial as it might appear at first sight. My suggestion at this point is to reform the way input # schema.graphql
# import type Car from './a.graphql'
type Query {
cars: [Car!]!
}
type Wheel {
id: ID!
name: String!
description: String!
price: Int!
}
# a.graphql
type Car {
id: ID!
model: String!
wheels: [Wheel!]!
}
type Wheel {
id: ID!
color: String!
} output type Query {
cars: [Car!]!
}
type Wheel {
id: ID!
name: String!
description: String!
price: Int!
}
type Car {
id: ID!
model: String!
wheels: [AWheel!]!
}
# AWheel specific to imported Car type
type AWheel {
id: ID!
color: String!
} |
Hey @maticzav. I just created this repro repository with tests https://github.com/amille14/graphql-import-tests (run As you can see, the first 3 tests are failing. These correspond to the 3 example cases I gave in my previous post. I added a 4th example case to show that |
Hi @ellipticaldoor and @amille14 ! |
Available in 1.0.0! |
On the documentation says that I can import certain types from a .graphql file like this:
But when I do that it, works like this other one:
I know this because if I reference a type that is not imported using the "Import specific types" I don't get an error, which is the behaviour I expect from reading the docs.
This are the dependencies I'm using:
I'm using apollo server, and this is how I pass the schema to the server.
The text was updated successfully, but these errors were encountered: