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

[1.0] WIP fix infer graphql input type #908

Closed
wants to merge 2 commits into from
Closed

[1.0] WIP fix infer graphql input type #908

wants to merge 2 commits into from

Conversation

0x80
Copy link
Contributor

@0x80 0x80 commented May 3, 2017

I still can't query object arrays from my data.

Managed to get a bit further but now my app complains Schema must contain unique named types but contains multiple types named "categoryTagsInputObject". And categoryTags in this case is the key that contains the object array in my data.

I'm sure it's something simple again, but I can't fully grasp it.

@gatsbybot
Copy link
Collaborator

gatsbybot commented May 3, 2017

Deploy preview failed.

Built with commit 9703e59

https://app.netlify.com/sites/gatsbygram/deploys/590a42716f4c505dfdfb6391

@gatsbybot
Copy link
Collaborator

gatsbybot commented May 3, 2017

Deploy preview failed.

Built with commit 9703e59

https://app.netlify.com/sites/gatsbyjs/deploys/590a426f6f4c505dfdfb638e

@gatsbybot
Copy link
Collaborator

gatsbybot commented May 3, 2017

Deploy preview ready!

Built with commit 9703e59

https://deploy-preview-908--using-drupal.netlify.com

@jquense
Copy link
Contributor

jquense commented May 3, 2017

I'd imagine that the problem is that the type is getting created multiple times in a loop somewhere. In general for the inference bits it may be helpful to have a type map/cache to avoid this sort of thing. E.g. you can only have 1 instance of a GraphQLType with the same name

@@ -24,6 +24,10 @@ describe(`GraphQL Input args`, () => {
title: `The world of dash and adventure`,
blue: 100,
},
anObjectArray: [
{ aString: `some string`, aNumber: 2, aBoolean: true },
{ aString: `some string`, aNumber: 2, anArray: [1, 2] },
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the idea that these are the same type but each is missing a different field?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question. I do think properties that hold an array should be able to be empty or not, but for starters I think it would be ok if objects always have to have the same keys. And if the data doesn't some out of the CMS like that it's still easy to fix in client code.

@KyleAMathews
Copy link
Contributor

Did you pull the latest code? I think I fixed the problem you're seeing yesterday in #897

@0x80
Copy link
Contributor Author

0x80 commented May 3, 2017

@KyleAMathews Yes this was based on the most recent code. There were no tests for object arrays yet for this part of the code.

@KyleAMathews
Copy link
Contributor

Ooo right this is for input code.

@KyleAMathews
Copy link
Contributor

Yeah you probably just need this then

const createTypeName = name => {

@0x80
Copy link
Contributor Author

0x80 commented May 3, 2017

@KyleAMathews yes that was the missing piece! 🎉

Going to wrap this up. I don't really know how to write the test for this. That one is still failing with the same message:

Expected value not to be defined, instead received
      [[GraphQLError: Cannot query field "anObjectArray" on type "TestConnection".]]]

But my application code is working. If you could have a look at the test to see if I did something stupid I can make the test pass maybe. Otherwise I'll just remove it for now.

@KyleAMathews
Copy link
Contributor

🎉

Lemme pull down your code real quick and see what's happening.

@0x80
Copy link
Contributor Author

0x80 commented May 3, 2017

@KyleAMathews I'm about to go to sleep. Will pick this up tomorrow morning. The last commit adds the createTypeName function. I made it shared (with one register). I assumed type names should be globally unique anyway.

@KyleAMathews
Copy link
Contributor

Here's the changes I made to get this working. I didn't use snapshots a lot elsewhere but they're a lot easier than fiddling with the long access chains.

fixes.patch

@KyleAMathews
Copy link
Contributor

Just got this in locally 7b45d92

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.

4 participants