I'm trying to generate a GraphQL schema.
I have the following Resolvers. The 3 of them are in different files. 2 of them are for gathering data while one of them is just a trigger API to have them collect more data from a data source.
@Resolver()
export class RefreshDataSchema{
constructor(
private readonly aggregatedDataService : AggregateDataService
){}
@Mutation(() => Boolean)
async refreshTransactions() : Promise<Boolean>{
Logger.info("Refresh transactions mutation received.");
return await this.aggregatedDataService.fetchAndAggregateTransactions();
}
@Mutation(() => Boolean)
async refreshAccounts() : Promise<Boolean>{
Logger.info("Refresh accounts mutation received.");
return await this.aggregatedDataService.fetchAndAggregateAccounts();
}
}
@Resolver(() => Account)
export class AccountSchema extends Account{
@Query(() => Account)
async getAccount(
@Arg('query', () => AccountQuery)
query: AccountQuery,
) {
const data = await Account.findOne({ where: query });
if (data === undefined) {
throw new Error(`Account for query "${JSON.stringify(query)}" could not be found!`);
}
return data;
}
@Query(() => [Account])
async getAccounts(
@Arg('query', () => AccountQuery)
query: AccountQuery,
@Arg('first', { defaultValue: 10 })
first: number = 10,
@Arg('offset', { defaultValue: 0 })
offset: number = 0,
) {
Logger.info(`GraphQL Query: get accounts. @First: ${first} @Offset: ${offset} received.`);
const data = Account.find({
take: first,
skip: offset,
order: { balance_in_cents: 'DESC' },
where: query,
});
if(data === undefined){
throw new Error(`Account for query "${JSON.stringify(query)}" could not be found!`);
}
return data;
}
};
@Resolver(() => Transaction)
export class TransactionSchema extends Transaction{
@Query(() => [Transaction])
async getTransactions(
@Arg('query', () => TransactionQuery)
query: TransactionQuery,
@Arg('first', { defaultValue: 10 })
first: number = 10,
@Arg('offset', { defaultValue: 0 })
offset: number = 0,
) {
Logger.info(`GraphQL Query: get transactions. @Query: ${query} @First: ${first} @Offset: ${offset} received.`);
try{
let data = await Transaction.find({
take: first,
skip: offset,
order: { executed_on: 'DESC' },
where: query
})
Logger.info("Transaction data retrieved succesfully.");
return data;
} catch(err) {
Logger.error(err);
return err;
}
}
}
And the code to generate the schema, which is federated, looks like this:
import { buildSchemaSync} from 'type-graphql';
import {createResolversMap} from 'type-graphql/dist/utils/createResolversMap';
import {
TransactionSchema, AccountSchema, RefreshDataSchema
} from '../graphql';
import { printSchema, buildFederatedSchema } from '@apollo/federation';
import { gql } from 'apollo-server-express';
const compiledSchema = buildSchemaSync({
resolvers: [
TransactionSchema,
AccountSchema,
RefreshDataSchema
],
});
export const schema = buildFederatedSchema(
{
typeDefs: gql(printSchema(compiledSchema)),
resolvers: createResolversMap(compiledSchema) as any
}
);
When I attempt to generate, the error I get is this:
Error: Schema must contain uniquely named types but contains multiple types named "DateTime".
Not sure where it's getting this "DateTime" from.
Thanks