babyfish-ct / graphql-ts-client

Typescript DSL for GraphQL.
MIT License
147 stars 20 forks source link

Uncaught Error: Illegal fetchable type "CustomerData", super class can only be specified for object type but its category is "EMBEDDED" #5

Closed wedreamer closed 2 years ago

wedreamer commented 2 years ago

Good brother, this library is very nice, very like to use, but encountered some problems, confused me

This is the relevant screenshot and code

code gen script

import { ApolloGenerator, loadRemoteSchema } from 'graphql-ts-client-codegen';
import { join } from 'path';

// https://github.com/babyfish-ct/graphql-ts-client/blob/master/doc/apollo_zh_CN.md
const generator = new ApolloGenerator({
  schemaLoader: async () => {
    return loadRemoteSchema(
      'https://ininderprint-backend-nestjs.cloud-dev.ininderprint.tw/vendor-api/graphql'
    );
  },
  targetDir: join(__dirname, '../src/gencode') as string,
  defaultFetcherExcludeMap: {
    // Department: ['avgSalary'],
  },
  scalarTypeMap: {
    String: 'string',
  },
});
generator.generate();

graphql req file

import { useTypedQuery } from 'gencode';
import { query$, userProfile$ } from 'gencode/fetchers';
import React from 'react';

export default function Orders() {
  const { data, loading, error } = useTypedQuery(
    query$.myProfile(
      userProfile$.userUuid.nickname.firstName.lastName.gender.birthday.avatar
    )
  );

  return (
    <>
      {loading && <div style={{ color: 'green' }}>Loading...</div>}
      {error && <div style={{ color: 'red' }}>Error</div>}
      <div>userUuid: {data?.myProfile.userUuid}</div>
      <div>userUuid: {data?.myProfile.nickname}</div>
      <div>userUuid: {data?.myProfile.firstName}</div>
      <div>userUuid: {data?.myProfile.lastName}</div>
      <div>userUuid: {data?.myProfile.gender}</div>
      <div>userUuid: {data?.myProfile.birthday}</div>
      <div>userUuid: {data?.myProfile.avatar}</div>
    </>
  );
}

screenshot relate info

oThG11.md.png

oThyct.md.png

oThfAg.md.png

Trouble brother,Thank you very much and good luck

wedreamer commented 2 years ago

oTfAsK.png

babyfish-ct commented 2 years ago

Give me your SDL please

BTW, your fetcher is too longer, you can try to use the default fetcher "userProfile$$"

wedreamer commented 2 years ago

this is my point https://ininderprint-backend-nestjs.cloud-dev.ininderprint.tw/vendor-api/graphql

i try use "userProfile$$" which also ,i also try add your wechat 🤣

wedreamer commented 2 years ago

Can we communicate directly by video, this is too inefficient 🚲

wedreamer commented 2 years ago

With the help of the author, the related problem was found, and the corresponding update is in v3.0.9,The document is related to doc, the reason is my graphql type has union type and this dont have ID