Skip to content

Commit

Permalink
fix imports in templates
Browse files Browse the repository at this point in the history
  • Loading branch information
timsuchanek committed Sep 19, 2019
1 parent dd72468 commit 2ac8030
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,42 +26,42 @@ test('exampleScript', async () => {
}`

expect(await exampleScript({ datamodel: schema, typescript: true })).toMatchInlineSnapshot(`
"/**
*
* This code was auto-generated based on the introspection result.
* Consider it a playground to explore the Photon API.
* Feel free to change it as much as you like or delete it altogether.
*
* The model \`User\` was randomly selected to demonstrate some API calls.
*
* Tip: Use the auto-completion of your editor to explore available API operations.
*
*/
"/**
*
* This code was auto-generated based on the introspection result.
* Consider it a playground to explore the Photon API.
* Feel free to change it as much as you like or delete it altogether.
*
* The model \`User\` was randomly selected to demonstrate some API calls.
*
* Tip: Use the auto-completion of your editor to explore available API operations.
*
*/
import Photon from '@generated/photon'
const photon = new Photon()
import { Photon } from '@generated/photon'
const photon = new Photon()
async function main() {
// Tip: Explore some arguments to \`findMany\`
const allUsers = await photon.users.findMany()
console.log(\`Retrieved all published users: \`, allUsers)
async function main() {
// Tip: Explore some arguments to \`findMany\`
const allUsers = await photon.users.findMany()
console.log(\`Retrieved all published users: \`, allUsers)
// Comment out the lines below to create a new User
// ATTENTION: This code creates a new record in your database
// const newUser = await photon.users.create({
// data: {
// // add some values here
// },
// })
// console.log(\`Created a new User: \`, newUser)
}
// Comment out the lines below to create a new User
// ATTENTION: This code creates a new record in your database
// const newUser = await photon.users.create({
// data: {
// // add some values here
// },
// })
// console.log(\`Created a new User: \`, newUser)
}
main()
.catch(e => console.error(e))
.finally(async () => {
await photon.disconnect()
})"
`)
main()
.catch(e => console.error(e))
.finally(async () => {
await photon.disconnect()
})"
`)

expect(await exampleScript({ datamodel: schema, typescript: false })).toMatchInlineSnapshot(`
"/**
Expand All @@ -76,7 +76,7 @@ test('exampleScript', async () => {
*
*/
const Photon = require('@generated/photon')
const { Photon } = require('@generated/photon')
const photon = new Photon()
async function main() {
Expand Down
2 changes: 1 addition & 1 deletion cli/introspection/src/prompt/utils/templates/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ main()
})`

const getImportStatement = es6 =>
es6 ? `import Photon from '@generated/photon'` : `const Photon = require('@generated/photon')`
es6 ? `import { Photon } from '@generated/photon'` : `const { Photon } = require('@generated/photon')`

export const exampleScript = async ({ typescript, datamodel }: { typescript: boolean; datamodel: string }) => {
const dmmf = await getDMMF({ datamodel })
Expand Down

0 comments on commit 2ac8030

Please sign in to comment.