teamwalnut / graphql-ppx

GraphQL language primitives for ReScript/ReasonML written in ReasonML
https://graphql-ppx.com
MIT License
257 stars 53 forks source link

The value use can’t be found in query #257

Closed dfalling closed 3 years ago

dfalling commented 3 years ago

I just dropped a dependency that’s unrelated to GraphQL that resulted in a ton dependencies being removed from my yarn.lock. For some reason this has also broken my GraphQL PPX:

   96 │ @react.component
   97 │ let make = () => {
   98 │   let queryResult = TripsQuery.use()
   99 │
  100 │   let intl = ReactIntl.useIntl()

  The value use can't be found in TripsQuery

My query's pretty simple:

%graphql(`
    query TripsQuery @ppxConfig(
    templateTagImport: "gql",
    templateTagLocation: "@apollo/client",
    templateTagIsFunction: true
  ){
      trips {
        id
        name
        startDate @ppxCustom(module: "Graphql.Date")
        endDate @ppxCustom(module: "Graphql.Date")
        bannerPhoto {
          small
        }
      }
    }
  `)

Any idea what would cause this? I've done clean builds and am not getting any errors for missing packages.

Thanks!

jfrolich commented 3 years ago

What is in your bsconfig.json? Use will be added to the query with the extendQuery configuration.

dfalling commented 3 years ago

Sorry I cross-posted in the rescript forum, I wasn't sure where was the better place for help with this. Happy to close either discussion.

My bsconfig is:

  ],
  "bs-dependencies": [
    "@reasonml-community/graphql-ppx"
  ],
  "ppx-flags": ["@reasonml-community/graphql-ppx/ppx"],
  "graphql": {
    "apolloMode": true,
    "extendMutation": "ExtendMutation",
    "extendQuery": "ExtendQuery",
    "extendSubscription": "ExtendSubscription",
    "templateTagReturnType": "templateTagReturnType",
    "templateTagImport": "gql",
    "templateTagLocation": "@apollo/client",
    "templateTagIsFunction": true
  },
dfalling commented 3 years ago

My bsconfig.json's flags still seem to have no effect, but using these for my query does work:

%graphql(`
    query TripsQuery @ppxConfig(
    templateTagImport: "gql",
    templateTagLocation: "@apollo/client",
    templateTagIsFunction: true,
    templateTagReturnType: "ApolloClient.GraphQL_PPX.templateTagReturnType",
    extend: "ApolloClient.GraphQL_PPX.ExtendQuery"
  ){
      ....
    }
  `)
jfrolich commented 3 years ago

What is the folder structure, it seems like the ppx can't find the configuration for some reason.

dfalling commented 3 years ago
.
├── bsconfig.json
├── graphql_schema.json
├── lib
│   └── bs
├── package.json
├── src
│   ├── App.bs.js
│   ├── App.res
│   └── views
│       ├── TripList.bs.js
│       ├── TripList.res # file with TripsQuery ppx
└── yarn.lock
jfrolich commented 3 years ago

if you put all configuration in the bsconfig.json instead of the query local config? Perhaps it doesn't play well together (I looked at the code again but they should work well together, but perhaps I missed something). Do you have a minimal reproducible example that you can share for me to look into?

dfalling commented 3 years ago

Yeah, if I strip my query down to just the query, I'm back to the use() is not defined error.

Here's a minimal example: https://github.com/dfalling/ppx_demo