Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test('RelationTransformer should fail if relation was with an object that is not a Model type.', () => {
const validSchema = `
type Test @model {
id: ID!
email: String!
testObj: Test1 @relation(fields: ["email"])
}
type Test1 {
id: ID!
name: String!
}
`
const transformer = new GraphQLTransform({
transformers: [
new DynamoDBModelTransformer(),
new RelationTransformer()
]
})
expect(() => transformer.transform(validSchema)).toThrowError(`Object type Test1 must be annotated with @model.`);
})
import { AppSyncTransformer } from "graphql-appsync-transformer";
import fs = require('fs');
const validSchema = `
type Post @model @searchable {
id: ID!
title: String!
upvotes: Int
downvotes: Int
percantageUp: Float
comments: [String]
isPublished: Boolean
}`;
const transformer = new GraphQLTransform({
transformers: [
new AppSyncTransformer(),
new DynamoDBModelTransformer(),
new SearchableModelTransformer()]
});
const out = transformer.transform(validSchema);
fs.writeFile('cf.out.json', JSON.stringify(out, null, 4), (err) => {
if (err) {
throw err;
}
console.log('SUCCESS!');
});
id: ID!
title: String!
upvotes: Int
downvotes: Int
percantageUp: Float
comments: [String]
isPublished: Boolean
}
type User @model {
id: ID!
name: String!
}
`;
const transformer = new GraphQLTransform({
transformers: [
new AppSyncTransformer(),
new DynamoDBModelTransformer()
]
});
const out = transformer.transform(validSchema);
fs.writeFile('cf.out.json', JSON.stringify(out, null, 4), (err) => {
if (err) {
throw err;
}
console.log('SUCCESS!');
});