Skip to content

Cannot make it work using vue-apollo #129

@FrancescoMussi

Description

@FrancescoMussi

Hello,
I am trying to make it working, but unsuccesfully.
Could you be so kind to check it out?

I am using @vue/apollo-composable 4.0.0-alpha.16

This is my code:

import { GetCountry , Country} from '../generated/graphql'

setup() {
  const route = useRoute()
  const code = route.params.code

  const { result, loading } = useQuery(GetCountry, {code: code}, { 
    clientId: 'default', 
    fetchPolicy: 'cache-first'
  });
  const country: Country = useResult(result, {}, (data) => data.country);
  console.log(country.continent)

  return {
    country,
    loading
  }
}

By assigning the type Country to the const country I get the following error:
Type 'Readonly<Ref<Readonly<any>>>' is missing the following properties from type 'Country': code, continent, emoji, emojiU, and 5 more.

This is Country and GetCountry from the generated code:

export type Country = {
  __typename?: 'Country';
  capital?: Maybe<Scalars['String']>;
  code: Scalars['ID'];
  continent: Continent;
  currency?: Maybe<Scalars['String']>;
  emoji: Scalars['String'];
  emojiU: Scalars['String'];
  languages: Array<Language>;
  name: Scalars['String'];
  native: Scalars['String'];
  phone: Scalars['String'];
  states: Array<State>;
};


export const GetCountry = gql`
    query getCountry($code: ID!) {
  country(code: $code) {
    code
    name
    native
    phone
    capital
    currency
    emoji
    continent {
      code
      name
    }
    languages {
      code
      name
    }
    states {
      code
      name
    }
  }
}

Am I doing something wrong?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions