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

Incompatible type error with 1.0.2-4911e5e.0 #222

Closed
dfalling opened this issue Nov 19, 2020 · 9 comments
Closed

Incompatible type error with 1.0.2-4911e5e.0 #222

dfalling opened this issue Nov 19, 2020 · 9 comments

Comments

@dfalling
Copy link

  This has type:
    Belt.List.t(TripsQuery.TripsQuery_inner.t_trips) (defined as
      list(TripsQuery.TripsQuery_inner.t_trips))
  Somewhere wanted: list(trip)
  
  The incompatible parts:
    TripsQuery.TripsQuery_inner.t_trips vs
    trip (defined as TripsQuery.t_trips)

This worked in 1.0.2-f9af62e.0, but not in 1.0.1. The full source of my component is:

[%graphql
  {|
    query TripsQuery @ppxConfig(
    templateTagImport: "gql",
    templateTagLocation: "@apollo/client",
    templateTagIsFunction: true
  ){
      trips {
        id
        name
      }
    }
  |}
];

type trip = TripsQuery.t_trips;

module TripItem = {
  [@react.component]
  let make = (~trip: trip) => {
    React.string(trip.name);
  };
};

[@react.component]
let make = () => {
  let queryResult = TripsQuery.use();

  let intl = ReactIntl.useIntl();
  let (trips, setTrips) = React.useState(_ => [||]);
  React.useEffect1(
    _ => {
      switch (queryResult.data) {
      | Some({trips}) => setTrips(_ => trips)
      | _ => ()
      };
      None;
    },
    [|queryResult|],
  );

  switch (queryResult, trips) {
  | ({loading: true}, _) => <Loading />
  | ({error: Some(error)}, _) => <div> {React.string(error.message)} </div>
  | (_, trips) =>
    <>
      {trips
       |> Array.map(trip => <TripItem trip key={trip.id} />)
       |> ReasonReact.array}
    </>
  };
};

And the error's happening on the |> Array.map(... line near the bottom.

@jfrolich
Copy link
Collaborator

You say it broke in 1.0.1 and works in 1.0.2-f9af62e.0, but the latter is a newer development version. Does that mean it is something that has been fixed in the newest version?

@dfalling
Copy link
Author

Sorry, I explained that poorly. Using that root type t_trips never worked until 1.0.2-x. Before I had to use that internal type of TripsQuery_inner.t_trips. So 1.0.2-4911e5e.0 is a regression for me to the behavior in 1.0.1.

@jfrolich
Copy link
Collaborator

@dfalling: The root type should be the type that is exposed. The reason that TripsQuery_inner.t_trips is there is because of the extension of the query module. We constrained the type to much in 1.0.0 so using TripsQuery.t_trips wouldn't work when you used the hook, which was fixed in 1.0.1. Why is this a regression for you?

@dfalling
Copy link
Author

@jfrolich In 1.0.2-4911e5e.0 I can no longer use the root exposed type. The type system now complains like it did in 1.0.1 that this type is incompatible with the expected type of TripsQuery_inner.t_trips. Am I misunderstanding these types? I had moved to 1.0.2x in order to use the root type.

@jfrolich
Copy link
Collaborator

Are you sure this is a bug in 1.0.1? Because we use this pattern a lot in 1.0.1 and there are no problems.

@jfrolich
Copy link
Collaborator

Can you remove the node modules and run npm install again. Sometimes an old version of the ppx is stuck.

@dfalling
Copy link
Author

Yes, this happens with a fresh build.

And sorry, I forgot why I bumped versions. This worked in 1.0.1 and in 1.0.2-f9af62e.0. I moved to 1.0.2 for the templateTagIsFunction.

@jfrolich
Copy link
Collaborator

jfrolich commented Nov 26, 2020

The diff (f9af62e...4911e5e) doesn't really add anything new. Can you try 1.0.2-b5c3318.0 because that one fixes an issue with upgrading the ppx (in the postinstall script). Besides 4911e5e is an old version that doesn't include the templateTagIsFunction yet!

@dfalling
Copy link
Author

1.0.2-b5c3318.0 works for me! Thanks!

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

No branches or pull requests

2 participants