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

Don't infer types for plugin provided GQL types #5497

Merged
merged 2 commits into from
May 31, 2018
Merged

Conversation

jquense
Copy link
Contributor

@jquense jquense commented May 21, 2018

This ended up optimizing code with the side benefit of fixing #5494

What this is doing is skipping inference for top level node keys where a plugin has already provided a type manually. Which should also mean that you get no warnings for JSON scalars

@jquense jquense requested a review from pieh May 21, 2018 16:23
@@ -37,7 +37,8 @@
"yargs": "^10.0.3"
},
"engines": {
"yarn": "^1.2.1"
"yarn": "^1.2.1",
"node": ">=6.11.5"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

i can remove this, but it's the minimum engine set by webpack4 so i figured it's the bottom of v2 support

@@ -34,7 +39,7 @@ const isEmptyObjectOrArray = (obj: any): boolean => {
const isScalar = val => !_.isObject(val) || val instanceof Date

const extractTypes = value => {
if (_.isArray(value)) {
if (Array.isArray(value)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

flow doesn't understand the lodash checks when choosing a branch on a mixed type

entries.map(entry => {
invariant(
Array.isArray(entry.value),
`this is validated in the previous call`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

solely to please flow, this should have already been checked at the call site


const example = {}
for (let key of allKeys) {
if (ignoreFields.includes(key)) continue
Copy link
Contributor Author

Choose a reason for hiding this comment

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

key line.

@@ -400,3 +407,7 @@ export function inferObjectStructureFromNodes({

return inferredFields
}

export function inferObjectStructureFromNodes(options: inferTypeOptions) {
Copy link
Contributor Author

@jquense jquense May 21, 2018

Choose a reason for hiding this comment

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

this is to prevent passing in exampleValue from the outside, it was always intended to be internal but existed as an arg for recursion's sake

@@ -5,6 +5,18 @@ const typeOf = require(`type-of`)
const util = require(`util`)
const { findRootNodeAncestor } = require(`./node-tracking`)

export type TypeConflictExample = {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I hopefully didn't change any logic in this file, i was trying to clean up the flow typing and swapped out plain object hashes for a Map, since it's likely to be faster

@KyleAMathews
Copy link
Contributor

Sounds/looks great to me! @pieh could you give this a review since you've been touching this code a lot more recently.

@pieh
Copy link
Contributor

pieh commented May 25, 2018 via email

@jquense
Copy link
Contributor Author

jquense commented May 30, 2018

friendly ping :)

Copy link
Contributor

@pieh pieh left a comment

Choose a reason for hiding this comment

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

Looks good (as expected :) ). Thanks for handling types!

Is this something we will want backport to master? (I would say yes)

@KyleAMathews
Copy link
Contributor

Is this something we will want backport to master? (I would say yes)

This is a problem as well in v1?

@jquense jquense merged commit ba6d6d7 into v2 May 31, 2018
@jquense
Copy link
Contributor Author

jquense commented May 31, 2018

The optimization could be backported easily enough, but i don't have a sense whether it's worth it. I'm not sure if the duplicate data warning has already been backported?

@jquense jquense deleted the tweak-inference-logic branch May 31, 2018 12:52
@pieh
Copy link
Contributor

pieh commented May 31, 2018

The optimization could be backported easily enough, but i don't have a sense whether it's worth it. I'm not sure if the duplicate data warning has already been backported?

It was added in PR against master ( #3905 ) and then merged in v2 with rest of master->v2 merges, so yeah I think we should add this to master.

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.

3 participants