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

[ShopifyVM] Use Functions App Management API for Dev Dash #4875

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion bin/get-graphql-schemas.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,13 @@ const schemas = [
pathToFile: 'areas/core/shopify/db/graphql/webhooks_schema_unstable_public.graphql',
localPath: './packages/app/src/cli/api/graphql/webhooks/webhooks_schema.graphql',
branch: 'dd',
}
},
{
repo: 'shopify',
pathToFile: 'areas/core/shopify/db/graphql/functions_cli_api_schema_unstable_public.graphql',
localPath: './packages/app/src/cli/api/graphql/functions/functions_cli_schema.graphql',
branch: 'dd',
},
]

function runCommand(command, args) {
Expand Down
1 change: 1 addition & 0 deletions graphql.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,6 @@ export default {
appManagement: projectFactory('app-management', 'app_management_schema.graphql'),
admin: projectFactory('admin', 'admin_schema.graphql', 'cli-kit'),
webhooks: projectFactory('webhooks', 'webhooks_schema.graphql'),
functions: projectFactory('functions', 'functions_cli_schema.graphql', 'app'),
},
}
26 changes: 21 additions & 5 deletions packages/app/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@
"{projectRoot}/src/cli/api/graphql/business-platform-organizations/generated/**/*.ts",
"{projectRoot}/src/cli/api/graphql/app-dev/generated/**/*.ts",
"{projectRoot}/src/cli/api/graphql/app-management/generated/**/*.ts",
"{projectRoot}/src/cli/api/graphql/webhooks/generated/**/*.ts"
"{projectRoot}/src/cli/api/graphql/webhooks/generated/**/*.ts",
"{projectRoot}/src/cli/api/graphql/functions/generated/**/*.ts"
],
"options": {
"commands": [
Expand All @@ -90,7 +91,8 @@
"pnpm eslint 'src/cli/api/graphql/business-platform-organizations/generated/**/*.{ts,tsx}' --fix",
"pnpm eslint 'src/cli/api/graphql/app-dev/generated/**/*.{ts,tsx}' --fix",
"pnpm eslint 'src/cli/api/graphql/app-management/generated/**/*.{ts,tsx}' --fix",
"pnpm eslint 'src/cli/api/graphql/webhooks/generated/**/*.{ts,tsx}' --fix"
"pnpm eslint 'src/cli/api/graphql/webhooks/generated/**/*.{ts,tsx}' --fix",
"pnpm eslint 'src/cli/api/graphql/functions/generated/**/*.{ts,tsx}' --fix"
],
"cwd": "packages/app"
}
Expand Down Expand Up @@ -161,6 +163,17 @@
"cwd": "{workspaceRoot}"
}
},
"graphql-codegen:generate:functions": {
"executor": "nx:run-commands",
"inputs": ["{workspaceRoot}/graphql.config.ts", "{projectRoot}/src/cli/api/graphql/functions/**/*.graphql"],
"outputs": ["{projectRoot}/src/cli/api/graphql/functions/generated/**/*.ts"],
"options": {
"commands": [
"pnpm exec graphql-codegen --project=functions"
],
"cwd": "{workspaceRoot}"
}
},
"graphql-codegen:postfix": {
"executor": "nx:run-commands",
"dependsOn": [
Expand All @@ -169,7 +182,8 @@
"graphql-codegen:generate:business-platform-organizations",
"graphql-codegen:generate:app-dev",
"graphql-codegen:generate:app-management",
"graphql-codegen:generate:webhooks"
"graphql-codegen:generate:webhooks",
"graphql-codegen:generate:functions"
],
"inputs": [{ "dependentTasksOutputFiles": "**/*.ts" }],
"outputs": [
Expand All @@ -178,7 +192,8 @@
"{projectRoot}/src/cli/api/graphql/business-platform-organizations/generated/**/*.ts",
"{projectRoot}/src/cli/api/graphql/app-dev/generated/**/*.ts",
"{projectRoot}/src/cli/api/graphql/app-management/generated/**/*.ts",
"{projectRoot}/src/cli/api/graphql/webhooks/generated/**/*.ts"
"{projectRoot}/src/cli/api/graphql/webhooks/generated/**/*.ts",
"{projectRoot}/src/cli/api/graphql/functions/generated/**/*.ts"
],
"options": {
"commands": [
Expand All @@ -187,7 +202,8 @@
"find ./packages/app/src/cli/api/graphql/business-platform-organizations/generated/ -type f -name '*.ts' -exec sh -c 'sed -i \"\" \"s|import \\* as Types from '\\''./types'\\'';|import \\* as Types from '\\''./types.js'\\'';|g; s|export const \\([A-Za-z0-9_]*\\)Document =|export const \\1 =|g\" \"$0\"' {} \\;",
"find ./packages/app/src/cli/api/graphql/app-dev/generated/ -type f -name '*.ts' -exec sh -c 'sed -i \"\" \"s|import \\* as Types from '\\''./types'\\'';|import \\* as Types from '\\''./types.js'\\'';|g; s|export const \\([A-Za-z0-9_]*\\)Document =|export const \\1 =|g\" \"$0\"' {} \\;",
"find ./packages/app/src/cli/api/graphql/app-management/generated/ -type f -name '*.ts' -exec sh -c 'sed -i \"\" \"s|import \\* as Types from '\\''./types'\\'';|import \\* as Types from '\\''./types.js'\\'';|g; s|export const \\([A-Za-z0-9_]*\\)Document =|export const \\1 =|g\" \"$0\"' {} \\;",
"find ./packages/app/src/cli/api/graphql/webhooks/generated/ -type f -name '*.ts' -exec sh -c 'sed -i \"\" \"s|import \\* as Types from '\\''./types'\\'';|import \\* as Types from '\\''./types.js'\\'';|g; s|export const \\([A-Za-z0-9_]*\\)Document =|export const \\1 =|g\" \"$0\"' {} \\;"
"find ./packages/app/src/cli/api/graphql/webhooks/generated/ -type f -name '*.ts' -exec sh -c 'sed -i \"\" \"s|import \\* as Types from '\\''./types'\\'';|import \\* as Types from '\\''./types.js'\\'';|g; s|export const \\([A-Za-z0-9_]*\\)Document =|export const \\1 =|g\" \"$0\"' {} \\;",
"find ./packages/app/src/cli/api/graphql/functions/generated/ -type f -name '*.ts' -exec sh -c 'sed -i \"\" \"s|import \\* as Types from '\\''./types'\\'';|import \\* as Types from '\\''./types.js'\\'';|g; s|export const \\([A-Za-z0-9_]*\\)Document =|export const \\1 =|g\" \"$0\"' {} \\;"
],
"cwd": "{workspaceRoot}"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,3 @@ export const ApiSchemaDefinitionQuery = gql`
export interface ApiSchemaDefinitionQuerySchema {
definition: string | null
}

export interface ApiSchemaDefinitionQueryVariables {
apiKey: string
version: string
type: string
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/* eslint-disable @typescript-eslint/consistent-type-definitions */
import * as Types from './types.js'

import {TypedDocumentNode as DocumentNode} from '@graphql-typed-document-node/core'

export type SchemaDefinitionByApiTypeQueryVariables = Types.Exact<{
type: Types.Scalars['String']['input']
version: Types.Scalars['String']['input']
}>

export type SchemaDefinitionByApiTypeQuery = {api?: {schema?: {definition: string} | null} | null}

export const SchemaDefinitionByApiType = {
kind: 'Document',
definitions: [
{
kind: 'OperationDefinition',
operation: 'query',
name: {kind: 'Name', value: 'SchemaDefinitionByApiType'},
variableDefinitions: [
{
kind: 'VariableDefinition',
variable: {kind: 'Variable', name: {kind: 'Name', value: 'type'}},
type: {kind: 'NonNullType', type: {kind: 'NamedType', name: {kind: 'Name', value: 'String'}}},
},
{
kind: 'VariableDefinition',
variable: {kind: 'Variable', name: {kind: 'Name', value: 'version'}},
type: {kind: 'NonNullType', type: {kind: 'NamedType', name: {kind: 'Name', value: 'String'}}},
},
],
selectionSet: {
kind: 'SelectionSet',
selections: [
{
kind: 'Field',
name: {kind: 'Name', value: 'api'},
arguments: [
{
kind: 'Argument',
name: {kind: 'Name', value: 'type'},
value: {kind: 'Variable', name: {kind: 'Name', value: 'type'}},
},
],
selectionSet: {
kind: 'SelectionSet',
selections: [
{
kind: 'Field',
name: {kind: 'Name', value: 'schema'},
arguments: [
{
kind: 'Argument',
name: {kind: 'Name', value: 'version'},
value: {kind: 'Variable', name: {kind: 'Name', value: 'version'}},
},
],
selectionSet: {
kind: 'SelectionSet',
selections: [
{kind: 'Field', name: {kind: 'Name', value: 'definition'}},
{kind: 'Field', name: {kind: 'Name', value: '__typename'}},
],
},
},
{kind: 'Field', name: {kind: 'Name', value: '__typename'}},
],
},
},
],
},
},
],
} as unknown as DocumentNode<SchemaDefinitionByApiTypeQuery, SchemaDefinitionByApiTypeQueryVariables>
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/* eslint-disable @typescript-eslint/consistent-type-definitions */
import * as Types from './types.js'

import {TypedDocumentNode as DocumentNode} from '@graphql-typed-document-node/core'

export type SchemaDefinitionByTargetQueryVariables = Types.Exact<{
handle: Types.Scalars['String']['input']
version: Types.Scalars['String']['input']
}>

export type SchemaDefinitionByTargetQuery = {target?: {api: {schema?: {definition: string} | null}} | null}

export const SchemaDefinitionByTarget = {
kind: 'Document',
definitions: [
{
kind: 'OperationDefinition',
operation: 'query',
name: {kind: 'Name', value: 'SchemaDefinitionByTarget'},
variableDefinitions: [
{
kind: 'VariableDefinition',
variable: {kind: 'Variable', name: {kind: 'Name', value: 'handle'}},
type: {kind: 'NonNullType', type: {kind: 'NamedType', name: {kind: 'Name', value: 'String'}}},
},
{
kind: 'VariableDefinition',
variable: {kind: 'Variable', name: {kind: 'Name', value: 'version'}},
type: {kind: 'NonNullType', type: {kind: 'NamedType', name: {kind: 'Name', value: 'String'}}},
},
],
selectionSet: {
kind: 'SelectionSet',
selections: [
{
kind: 'Field',
name: {kind: 'Name', value: 'target'},
arguments: [
{
kind: 'Argument',
name: {kind: 'Name', value: 'handle'},
value: {kind: 'Variable', name: {kind: 'Name', value: 'handle'}},
},
],
selectionSet: {
kind: 'SelectionSet',
selections: [
{
kind: 'Field',
name: {kind: 'Name', value: 'api'},
selectionSet: {
kind: 'SelectionSet',
selections: [
{
kind: 'Field',
name: {kind: 'Name', value: 'schema'},
arguments: [
{
kind: 'Argument',
name: {kind: 'Name', value: 'version'},
value: {kind: 'Variable', name: {kind: 'Name', value: 'version'}},
},
],
selectionSet: {
kind: 'SelectionSet',
selections: [
{kind: 'Field', name: {kind: 'Name', value: 'definition'}},
{kind: 'Field', name: {kind: 'Name', value: '__typename'}},
],
},
},
{kind: 'Field', name: {kind: 'Name', value: '__typename'}},
],
},
},
{kind: 'Field', name: {kind: 'Name', value: '__typename'}},
],
},
},
],
},
},
],
} as unknown as DocumentNode<SchemaDefinitionByTargetQuery, SchemaDefinitionByTargetQueryVariables>
24 changes: 24 additions & 0 deletions packages/app/src/cli/api/graphql/functions/generated/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* eslint-disable @typescript-eslint/consistent-type-definitions, @typescript-eslint/naming-convention */
export type Maybe<T> = T | null
export type InputMaybe<T> = Maybe<T>
export type Exact<T extends {[key: string]: unknown}> = {[K in keyof T]: T[K]}
export type MakeOptional<T, K extends keyof T> = Omit<T, K> & {[SubKey in K]?: Maybe<T[SubKey]>}
export type MakeMaybe<T, K extends keyof T> = Omit<T, K> & {[SubKey in K]: Maybe<T[SubKey]>}
export type MakeEmpty<T extends {[key: string]: unknown}, K extends keyof T> = {[_ in K]?: never}
export type Incremental<T> = T | {[P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never}
/** All built-in and custom scalars, mapped to their actual values */
export type Scalars = {
ID: {input: string; output: string}
String: {input: string; output: string}
Boolean: {input: boolean; output: boolean}
Int: {input: number; output: number}
Float: {input: number; output: number}
/**
* Represents an [RFC 3986](https://datatracker.ietf.org/doc/html/rfc3986) and
* [RFC 3987](https://datatracker.ietf.org/doc/html/rfc3987)-compliant URI string.
*
* For example, `"https://example.myshopify.com"` is a valid URL. It includes a scheme (`https`) and a host
* (`example.myshopify.com`).
*/
URL: {input: string; output: string}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
query SchemaDefinitionByApiType($type: String!, $version: String!) {
api(type: $type) {
schema(version: $version) {
definition
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
query SchemaDefinitionByTarget($handle: String!, $version: String!) {
target(handle: $handle) {
api {
schema(version: $version) {
definition
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,3 @@ export const TargetSchemaDefinitionQuery = gql`
export interface TargetSchemaDefinitionQuerySchema {
definition: string | null
}

export interface TargetSchemaDefinitionQueryVariables {
apiKey: string
version: string
target: string
}
4 changes: 2 additions & 2 deletions packages/app/src/cli/commands/app/function/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
userProvidedConfigName: flags.config,
apiKey: flags['client-id'],
reset: flags.reset,
callback: async (app, developerPlatformClient, ourFunction) => {
callback: async (app, developerPlatformClient, ourFunction, orgId) => {
let functionExport = DEFAULT_FUNCTION_EXPORT

if (flags.export !== undefined) {
Expand All @@ -56,7 +56,7 @@
if (targeting.length > 1 && isTTY({})) {
const targets = targeting.map((target) => ({
label: target.target,
value: target.export || DEFAULT_FUNCTION_EXPORT,

Check warning on line 59 in packages/app/src/cli/commands/app/function/run.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/app/src/cli/commands/app/function/run.ts#L59

[@typescript-eslint/prefer-nullish-coalescing] Prefer using nullish coalescing operator (`??`) instead of a logical or (`||`), as it is a safer operator.
}))

functionExport = await renderAutocompletePrompt({
Expand All @@ -64,7 +64,7 @@
choices: targets,
})
} else {
functionExport = targeting?.[0]?.export || DEFAULT_FUNCTION_EXPORT

Check warning on line 67 in packages/app/src/cli/commands/app/function/run.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/app/src/cli/commands/app/function/run.ts#L67

[@typescript-eslint/prefer-nullish-coalescing] Prefer using nullish coalescing operator (`??`) instead of a logical or (`||`), as it is a safer operator.
outputDebug(
`Using export '${functionExport}'. Use the --export flag or an interactive terminal to select a different export.`,
)
Expand All @@ -77,7 +77,7 @@

const inputQueryPath = ourFunction?.configuration.targeting?.[0]?.input_query
const queryPath = inputQueryPath && `${ourFunction?.directory}/${inputQueryPath}`
const schemaPath = await getOrGenerateSchemaPath(ourFunction, app, developerPlatformClient)
const schemaPath = await getOrGenerateSchemaPath(ourFunction, app, developerPlatformClient, orgId)

await runFunction({
functionExtension: ourFunction,
Expand Down
3 changes: 2 additions & 1 deletion packages/app/src/cli/commands/app/function/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,14 @@ export default class FetchSchema extends AppCommand {
apiKey,
reset: flags.reset,
userProvidedConfigName: flags.config,
callback: async (app, developerPlatformClient, ourFunction) => {
callback: async (app, developerPlatformClient, ourFunction, orgId) => {
await generateSchemaService({
app,
extension: ourFunction,
developerPlatformClient,
stdout: flags.stdout,
path: flags.path,
orgId,
})
return app
},
Expand Down
10 changes: 6 additions & 4 deletions packages/app/src/cli/models/app/app.test-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ import {
} from '../../api/graphql/extension_migrate_flow_extension.js'
import {UpdateURLsSchema, UpdateURLsVariables} from '../../api/graphql/update_urls.js'
import {CurrentAccountInfoSchema} from '../../api/graphql/current_account_info.js'
import {TargetSchemaDefinitionQueryVariables} from '../../api/graphql/functions/target_schema_definition.js'
import {ApiSchemaDefinitionQueryVariables} from '../../api/graphql/functions/api_schema_definition.js'
import {
MigrateToUiExtensionSchema,
MigrateToUiExtensionVariables,
Expand All @@ -69,6 +67,8 @@ import {
ExtensionUpdateDraftMutation,
ExtensionUpdateDraftMutationVariables,
} from '../../api/graphql/partners/generated/update-draft.js'
import {SchemaDefinitionByTargetQueryVariables} from '../../api/graphql/functions/generated/schema-definition-by-target.js'
import {SchemaDefinitionByApiTypeQueryVariables} from '../../api/graphql/functions/generated/schema-definition-by-api-type.js'
import {vi} from 'vitest'
import {joinPath} from '@shopify/cli-kit/node/path'

Expand Down Expand Up @@ -1351,8 +1351,10 @@ export function testDeveloperPlatformClient(stubs: Partial<DeveloperPlatformClie
migrateAppModule: (_input: MigrateAppModuleVariables) => Promise.resolve(migrateAppModuleResponse),
updateURLs: (_input: UpdateURLsVariables) => Promise.resolve(updateURLsResponse),
currentAccountInfo: () => Promise.resolve(currentAccountInfoResponse),
targetSchemaDefinition: (_input: TargetSchemaDefinitionQueryVariables) => Promise.resolve('schema'),
apiSchemaDefinition: (_input: ApiSchemaDefinitionQueryVariables) => Promise.resolve('schema'),
targetSchemaDefinition: (_input: SchemaDefinitionByTargetQueryVariables & {apiKey?: string}, _orgId: string) =>
Promise.resolve('schema'),
apiSchemaDefinition: (_input: SchemaDefinitionByApiTypeQueryVariables & {apiKey?: string}, _orgId: string) =>
Promise.resolve('schema'),
migrateToUiExtension: (_input: MigrateToUiExtensionVariables) => Promise.resolve(migrateToUiExtensionResponse),
toExtensionGraphQLType: (input: string) => input,
subscribeToAppLogs: (_input: AppLogsSubscribeVariables) => Promise.resolve(appLogsSubscribeResponse),
Expand Down
4 changes: 2 additions & 2 deletions packages/app/src/cli/services/function/common.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ describe('getOrGenerateSchemaPath', () => {
vi.mocked(fileExists).mockResolvedValue(true)

// When
const result = await getOrGenerateSchemaPath(extension, app, developerPlatformClient)
const result = await getOrGenerateSchemaPath(extension, app, developerPlatformClient, '123')

// Then
expect(result).toBe(expectedPath)
Expand All @@ -133,7 +133,7 @@ describe('getOrGenerateSchemaPath', () => {
vi.mocked(fileExists).mockResolvedValueOnce(true)

// When
const result = await getOrGenerateSchemaPath(extension, app, developerPlatformClient)
const result = await getOrGenerateSchemaPath(extension, app, developerPlatformClient, '123')

// Then
expect(result).toBe(expectedPath)
Expand Down
Loading
Loading