Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement autoCodeGen vite plugin option #1385

Closed
wants to merge 9 commits into from

Conversation

ewen-lbh
Copy link
Contributor

@ewen-lbh ewen-lbh commented Nov 9, 2024

To help everyone out, please make sure your PR does the following:

  • Update the first line to point to the ticket that this PR fixes
  • Add a message that clearly describes the fix
  • If applicable, add a test that would fail without this fix
  • Make sure the unit and integration tests pass locally with pnpm run tests and cd integration && pnpm run tests
  • Includes a changeset if your fix affects the user with pnpm changeset

Copy link

changeset-bot bot commented Nov 9, 2024

🦋 Changeset detected

Latest commit: 6625779

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 8 packages
Name Type
houdini Minor
houdini-adapter-auto Patch
houdini-adapter-cloudflare Patch
houdini-adapter-node Patch
houdini-adapter-static Patch
houdini-react Patch
houdini-svelte Patch
houdini-plugin-svelte-global-stores Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

netlify bot commented Nov 9, 2024

Deploy Preview for houdini-docs-next canceled.

Name Link
🔨 Latest commit 6625779
🔍 Latest deploy log https://app.netlify.com/sites/houdini-docs-next/deploys/67321ef72e2a8a00082039a8

Copy link

netlify bot commented Nov 9, 2024

Deploy Preview for houdinigraphql canceled.

Name Link
🔨 Latest commit 6625779
🔍 Latest deploy log https://app.netlify.com/sites/houdinigraphql/deploys/67321ef70c00890008e4335a

@ewen-lbh ewen-lbh force-pushed the autocodegen-options branch from 2e26c1e to d152a99 Compare November 9, 2024 17:49
@ewen-lbh
Copy link
Contributor Author

ewen-lbh commented Nov 9, 2024

Okay, autoCodeGen: "smart" works!

The first change in a file site the dev server was started still triggers a reload because we don't know the documents yet, but as the devserver stays up, subsequent changes to the same file only trigger a full-page reload when a graphql document changes!

@ewen-lbh
Copy link
Contributor Author

ewen-lbh commented Nov 9, 2024

I removed my console.logs, but it looks like this:

# the quiet option for watchAndRun seems to be removed from kitql-watch-and-run...
 Watch-and-Run  ✔ Watch change 100ms
# changeing code in a svelte file
codegen? /home/uwun/projects.local/churros/packages/app/src/routes/(app)/events/[id]/edit/managers/+page.svelte
{
  absolutePath: '/home/uwun/projects.local/churros/packages/app/src/routes/(app)/events/[id]/edit/managers/+page.svelte',
  documents: {
    PageEventEditManager_ManagerUpdates: 'subscription PageEventEditManager_ManagerUpdates($event: LocalID!) {\n' +
      '      event(id: $event) {\n' +
      '        managers {\n' +
      '          user {\n' +
      '            uid\n' +
      '          }\n' +
      '          usedInvite {\n' +
      '            usesLeft\n' +
      '            unusable\n' +
      '          }\n' +
      '          ...PageEventEditManagers_ItemManager\n' +
      '        }\n' +
      '      }\n' +
      '    }',
    AddEventManager: 'mutation AddEventManager($user: UID!, $event: LocalID!, $power: EventManagerPowerLevel!) {\n' +
      '      upsertEventManager(user: $user, event: $event, powerlevel: $power) {\n' +
      '        ... on MutationUpsertEventManagerSuccess {\n' +
      '          data {\n' +
      '            id\n' +
      '            ...List_EventManagers_insert\n' +
      '          }\n' +
      '        }\n' +
      '        ...MutationErrors\n' +
      '      }\n' +
      '    }',
    CreateEventManagerInvite: 'mutation CreateEventManagerInvite(\n' +
      '      $event: LocalID!\n' +
      '      $power: EventManagerPowerLevel!\n' +
      '      $capacity: Capacity!\n' +
      '      $expiresAt: DateTime\n' +
      '    ) {\n' +
      '      upsertEventManagerInvite(\n' +
      '        event: $event\n' +
      '        input: { capacity: $capacity, expiresAt: $expiresAt, powerlevel: $power }\n' +
      '      ) {\n' +
      '        ... on MutationUpsertEventManagerInviteSuccess {\n' +
      '          data {\n' +
      '            id\n' +
      '            ...List_EventManagerInvites_insert @prepend\n' +
      '          }\n' +
      '        }\n' +
      '        ...MutationErrors\n' +
      '      }\n' +
      '    }'
  }
}
Skipped codegen for /home/uwun/projects.local/churros/packages/app/src/routes/(app)/events/[id]/edit/managers/+page.svelte since graphql documents did not change
# changeing a mutation store definition in that same file
 Watch-and-Run  ✔ Watch change 100ms
codegen? /home/uwun/projects.local/churros/packages/app/src/routes/(app)/events/[id]/edit/managers/+page.svelte
{
  absolutePath: '/home/uwun/projects.local/churros/packages/app/src/routes/(app)/events/[id]/edit/managers/+page.svelte',
  documents: {
    PageEventEditManager_ManagerUpdates: 'subscription PageEventEditManager_ManagerUpdates($event: LocalID!) {\n' +
      '      event(id: $event) {\n' +
      '        managers {\n' +
      '          user {\n' +
      '            uid\n' +
      '          }\n' +
      '          usedInvite {\n' +
      '            usesLeft\n' +
      '            unusable\n' +
      '          }\n' +
      '          ...PageEventEditManagers_ItemManager\n' +
      '        }\n' +
      '      }\n' +
      '    }',
    AddEventManager: 'mutation AddEventManager($user: UID!, $event: LocalID!, $power: EventManagerPowerLevel!) {\n' +
      '      upsertEventManager(user: $user, event: $event, powerlevel: $power) {\n' +
      '        ... on MutationUpsertEventManagerSuccess {\n' +
      '          data {\n' +
      '            id\n' +
      '            localID\n' +
      '            ...List_EventManagers_insert\n' +
      '          }\n' +
      '        }\n' +
      '        ...MutationErrors\n' +
      '      }\n' +
      '    }',
    CreateEventManagerInvite: 'mutation CreateEventManagerInvite(\n' +
      '      $event: LocalID!\n' +
      '      $power: EventManagerPowerLevel!\n' +
      '      $capacity: Capacity!\n' +
      '      $expiresAt: DateTime\n' +
      '    ) {\n' +
      '      upsertEventManagerInvite(\n' +
      '        event: $event\n' +
      '        input: { capacity: $capacity, expiresAt: $expiresAt, powerlevel: $power }\n' +
      '      ) {\n' +
      '        ... on MutationUpsertEventManagerInviteSuccess {\n' +
      '          data {\n' +
      '            id\n' +
      '            ...List_EventManagerInvites_insert @prepend\n' +
      '          }\n' +
      '        }\n' +
      '        ...MutationErrors\n' +
      '      }\n' +
      '    }'
  }
}
Regenerating runtime because /home/uwun/projects.local/churros/packages/app/src/routes/(app)/events/[id]/edit/managers/+page.svelte changed

@ewen-lbh ewen-lbh force-pushed the autocodegen-options branch from 2dda139 to ebd937b Compare November 10, 2024 15:09
@ewen-lbh ewen-lbh marked this pull request as ready for review November 11, 2024 15:11
* @param source the source code
* @returns an object mapping document names to their content
*/
export function extractDocuments(source: string): Record<string, string> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should rely on a shared function with the collectDocuments part of the codegen pipeline. Plugins can define their own logic for what it means to extract a document out of a file and we need to make sure we're picking them up.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the function is not currently exported -- exporting it is fine i guess?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also it goes thru every file, whereas i only need a single file, i'll add a variadic arg to specify source locations, tell me if you want it another way (such as breaking up collectDocuments into more functions)

]

const codegen = async (_server: ViteDevServer | undefined, absolutePath: string | null) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this to its own file?

} else if (fileContents) {
const previousDocuments = extractedDocuments[absolutePath]
if (!previousDocuments) {
// To prevent full-page reloads every time we change something in a new document, just don't reload.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could be confusing - if the file changes, we should generate. Waiting til a second update will feel clunky if someone is putting a quick demo together where they are copying and pasting entire file contents

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i was actually on the fence for this, but i think i aggree with you after all haha

@AlecAivazis
Copy link
Collaborator

@ewen-lbh any updates here? happy to revisit this when you're ready to see it through

@ewen-lbh
Copy link
Contributor Author

hi! i'm hoping to get back to it this weekend, exams have been piling up cuz it's almost the end of the semester '^^

@AlecAivazis
Copy link
Collaborator

I'm going to close this for now. feel free to re-open this effort when you have time @ewen-lbh

@ewen-lbh
Copy link
Contributor Author

hiii can you reopen the pr? i committed the changes and verified it works on a real life project ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants