mickhansen / graphql-sequelize

GraphQL & Relay for MySQL & Postgres via Sequelize
MIT License
1.9k stars 172 forks source link

simplifyAST -> simplifyValue tries to access undefined info.variableValues #530

Closed RichAyotte closed 6 years ago

RichAyotte commented 6 years ago

info.variableValues in the simplifyValue can be undefined and throw:

Cannot read property 'order' of undefined
    TypeError: Cannot read property 'order' of undefined
        at simplifyValue (/home/rich/Projects/omn/backend/node_modules/graphql-sequelize/lib/simplifyAST.js:50:31)
        at /home/rich/Projects/omn/backend/node_modules/graphql-sequelize/lib/simplifyAST.js:95:30
        at Array.reduce (<anonymous>)
        at selections.reduce.fields (/home/rich/Projects/omn/backend/node_modules/graphql-sequelize/lib/simplifyAST.js:94:54)
        at Array.reduce (<anonymous>)
        at simplifyAST (/home/rich/Projects/omn/backend/node_modules/graphql-sequelize/lib/simplifyAST.js:77:21)
        at selections.reduce.fields (/home/rich/Projects/omn/backend/node_modules/graphql-sequelize/lib/simplifyAST.js:88:62)
        at Array.reduce (<anonymous>)
        at simplifyAST (/home/rich/Projects/omn/backend/node_modules/graphql-sequelize/lib/simplifyAST.js:77:21)
        at selections.reduce.fields (/home/rich/Projects/omn/backend/node_modules/graphql-sequelize/lib/simplifyAST.js:88:62)
        at Array.reduce (<anonymous>)
        at simplifyAST (/home/rich/Projects/omn/backend/node_modules/graphql-sequelize/lib/simplifyAST.js:77:21)
        at Object.beforeResolve [as before] (/home/rich/Projects/omn/backend/schema.js:89:15)
        at resolver (/home/rich/Projects/omn/backend/node_modules/graphql-sequelize/lib/resolver.js:81:47)
        at resolveFieldValueOrError (/home/rich/Projects/omn/backend/node_modules/graphql/execution/execute.js:498:12)
        at resolveField (/home/rich/Projects/omn/backend/node_modules/graphql/execution/execute.js:462:16)
        at /home/rich/Projects/omn/backend/node_modules/graphql/execution/execute.js:311:18
        at Array.reduce (<anonymous>)
        at executeFields (/home/rich/Projects/omn/backend/node_modules/graphql/execution/execute.js:308:42)
        at executeOperation (/home/rich/Projects/omn/backend/node_modules/graphql/execution/execute.js:236:122)
        at executeImpl (/home/rich/Projects/omn/backend/node_modules/graphql/execution/execute.js:133:26)
        at execute (/home/rich/Projects/omn/backend/node_modules/graphql/execution/execute.js:110:229)

Here's an example gql query:

query ($order: String, $limit: Int) {
  SystemPerson {
    CompanyRoles {
      Company(order: $order, limit: $limit) {
        label: name
        value: id
        __typename
      }
      __typename
    }
    __typename
  }
}

parses to:

{
  "hostname": "cheetah"
  , "pid": 7850
  , "level": 20
  , "kind": "OperationDefinition"
  , "operation": "query"
  , "variableDefinitions": [{
    "kind": "VariableDefinition"
    , "variable": {
      "kind": "Variable"
      , "name": {
        "kind": "Name"
        , "value": "order"
        , "loc": {
          "start": 8
          , "end": 13
        }
      }
      , "loc": {
        "start": 7
        , "end": 13
      }
    }
    , "type": {
      "kind": "NamedType"
      , "name": {
        "kind": "Name"
        , "value": "String"
        , "loc": {
          "start": 15
          , "end": 21
        }
      }
      , "loc": {
        "start": 15
        , "end": 21
      }
    }
    , "defaultValue": null
    , "loc": {
      "start": 7
      , "end": 21
    }
  }, {
    "kind": "VariableDefinition"
    , "variable": {
      "kind": "Variable"
      , "name": {
        "kind": "Name"
        , "value": "limit"
        , "loc": {
          "start": 24
          , "end": 29
        }
      }
      , "loc": {
        "start": 23
        , "end": 29
      }
    }
    , "type": {
      "kind": "NamedType"
      , "name": {
        "kind": "Name"
        , "value": "Int"
        , "loc": {
          "start": 31
          , "end": 34
        }
      }
      , "loc": {
        "start": 31
        , "end": 34
      }
    }
    , "defaultValue": null
    , "loc": {
      "start": 23
      , "end": 34
    }
  }]
  , "directives": []
  , "selectionSet": {
    "kind": "SelectionSet"
    , "selections": [{
      "kind": "Field"
      , "alias": null
      , "name": {
        "kind": "Name"
        , "value": "SystemPerson"
        , "loc": {
          "start": 40
          , "end": 52
        }
      }
      , "arguments": []
      , "directives": []
      , "selectionSet": {
        "kind": "SelectionSet"
        , "selections": [{
          "kind": "Field"
          , "alias": null
          , "name": {
            "kind": "Name"
            , "value": "CompanyRoles"
            , "loc": {
              "start": 59
              , "end": 71
            }
          }
          , "arguments": []
          , "directives": []
          , "selectionSet": {
            "kind": "SelectionSet"
            , "selections": [{
              "kind": "Field"
              , "alias": null
              , "name": {
                "kind": "Name"
                , "value": "Company"
                , "loc": {
                  "start": 80
                  , "end": 87
                }
              }
              , "arguments": [{
                "kind": "Argument"
                , "name": {
                  "kind": "Name"
                  , "value": "order"
                  , "loc": {
                    "start": 88
                    , "end": 93
                  }
                }
                , "value": {
                  "kind": "Variable"
                  , "name": {
                    "kind": "Name"
                    , "value": "order"
                    , "loc": {
                      "start": 96
                      , "end": 101
                    }
                  }
                  , "loc": {
                    "start": 95
                    , "end": 101
                  }
                }
                , "loc": {
                  "start": 88
                  , "end": 101
                }
              }, {
                "kind": "Argument"
                , "name": {
                  "kind": "Name"
                  , "value": "limit"
                  , "loc": {
                    "start": 103
                    , "end": 108
                  }
                }
                , "value": {
                  "kind": "Variable"
                  , "name": {
                    "kind": "Name"
                    , "value": "limit"
                    , "loc": {
                      "start": 111
                      , "end": 116
                    }
                  }
                  , "loc": {
                    "start": 110
                    , "end": 116
                  }
                }
                , "loc": {
                  "start": 103
                  , "end": 116
                }
              }]
              , "directives": []
              , "selectionSet": {
                "kind": "SelectionSet"
                , "selections": [{
                  "kind": "Field"
                  , "alias": {
                    "kind": "Name"
                    , "value": "label"
                    , "loc": {
                      "start": 128
                      , "end": 133
                    }
                  }
                  , "name": {
                    "kind": "Name"
                    , "value": "name"
                    , "loc": {
                      "start": 135
                      , "end": 139
                    }
                  }
                  , "arguments": []
                  , "directives": []
                  , "selectionSet": null
                  , "loc": {
                    "start": 128
                    , "end": 139
                  }
                }, {
                  "kind": "Field"
                  , "alias": {
                    "kind": "Name"
                    , "value": "value"
                    , "loc": {
                      "start": 148
                      , "end": 153
                    }
                  }
                  , "name": {
                    "kind": "Name"
                    , "value": "id"
                    , "loc": {
                      "start": 155
                      , "end": 157
                    }
                  }
                  , "arguments": []
                  , "directives": []
                  , "selectionSet": null
                  , "loc": {
                    "start": 148
                    , "end": 157
                  }
                }, {
                  "kind": "Field"
                  , "alias": null
                  , "name": {
                    "kind": "Name"
                    , "value": "__typename"
                    , "loc": {
                      "start": 166
                      , "end": 176
                    }
                  }
                  , "arguments": []
                  , "directives": []
                  , "selectionSet": null
                  , "loc": {
                    "start": 166
                    , "end": 176
                  }
                }]
                , "loc": {
                  "start": 118
                  , "end": 184
                }
              }
              , "loc": {
                "start": 80
                , "end": 184
              }
            }, {
              "kind": "Field"
              , "alias": null
              , "name": {
                "kind": "Name"
                , "value": "__typename"
                , "loc": {
                  "start": 191
                  , "end": 201
                }
              }
              , "arguments": []
              , "directives": []
              , "selectionSet": null
              , "loc": {
                "start": 191
                , "end": 201
              }
            }]
            , "loc": {
              "start": 72
              , "end": 207
            }
          }
          , "loc": {
            "start": 59
            , "end": 207
          }
        }, {
          "kind": "Field"
          , "alias": null
          , "name": {
            "kind": "Name"
            , "value": "__typename"
            , "loc": {
              "start": 212
              , "end": 222
            }
          }
          , "arguments": []
          , "directives": []
          , "selectionSet": null
          , "loc": {
            "start": 212
            , "end": 222
          }
        }]
        , "loc": {
          "start": 53
          , "end": 226
        }
      }
      , "loc": {
        "start": 40
        , "end": 226
      }
    }]
    , "loc": {
      "start": 36
      , "end": 228
    }
  }
  , "loc": {
    "start": 0
    , "end": 228
  }
  , "msg": ""
  , "time": "2017-10-16T13:31:54.917Z"
  , "src": {
    "file": "/home/rich/Projects/omn/backend/schema.js"
    , "line": 94
    , "func": "beforeResolve"
  }
  , "v": 0
}
codecov-io commented 6 years ago

Codecov Report

Merging #530 into master will not change coverage. The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #530   +/-   ##
=======================================
  Coverage   95.03%   95.03%           
=======================================
  Files          11       11           
  Lines         383      383           
=======================================
  Hits          364      364           
  Misses         19       19
Impacted Files Coverage Δ
src/simplifyAST.js 92.72% <100%> (ø) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update bfaaf49...c4da13e. Read the comment docs.

RichAyotte commented 6 years ago

@mickhansen Any thoughts on this?

mickhansen commented 6 years ago

Thanks @RichAyotte, and sorry for slow response. v5.4.3

RichAyotte commented 6 years ago

Thanks for the merge and no worries! I appreciate all the work that goes into this.