Skip to content

Commit

Permalink
Merge pull request #81 from replicatedhq/laverya/const-graphql-queries
Browse files Browse the repository at this point in the history
all graphql queries should be const strings for ease of testing
  • Loading branch information
laverya authored Dec 4, 2019
2 parents 899342f + 6d30e32 commit 0176226
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 133 deletions.
40 changes: 21 additions & 19 deletions pkg/kotsclient/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,31 @@ type KotsApp struct {
Channels []*KotsAppChannelData `json: "channels"`
}

const listAppsQuery = `
query kots {
kots {
apps {
id
name
created
updated
isDefault
isArchived
slug
channels {
id
}
isKotsApp
}
}
}
`

func (c *GraphQLClient) ListApps() ([]types.AppAndChannels, error) {
response := GraphQLResponseListApps{}

request := graphql.Request{
Query: `
query kots {
kots {
apps {
id
name
created
updated
isDefault
isArchived
slug
channels {
id
}
isKotsApp
}
}
}
`,
Query: listAppsQuery,

Variables: map[string]interface{}{},
}
Expand Down
138 changes: 71 additions & 67 deletions pkg/kotsclient/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,61 +41,63 @@ type KotsChannel struct {
CurrentVersion string `json:"currentVersion"`
}

func (c *GraphQLClient) ListChannels(appID string) ([]types.Channel, error) {
response := GraphQLResponseListChannels{}

request := graphql.Request{
Query: `
query getKotsAppChannels($appId: ID!) {
getKotsAppChannels(appId: $appId) {
const listChannelsQuery = `
query getKotsAppChannels($appId: ID!) {
getKotsAppChannels(appId: $appId) {
id
appId
name
currentVersion
channelSequence
releaseSequence
currentReleaseDate
numReleases
description
channelIcon
created
updated
isDefault
isArchived
adoptionRate {
releaseSequence
semver
count
percent
totalOnChannel
}
customers {
id
appId
name
currentVersion
channelSequence
releaseSequence
currentReleaseDate
numReleases
description
channelIcon
avatar
shipInstallStatus {
status
}
}
githubRef {
owner
repoFullName
branch
path
}
releases {
semver
releaseNotes
created
updated
isDefault
isArchived
adoptionRate {
releaseSequence
semver
count
percent
totalOnChannel
}
customers {
id
name
avatar
shipInstallStatus {
status
}
}
githubRef {
owner
repoFullName
branch
path
}
releases {
semver
releaseNotes
created
updated
releasedAt
sequence
channelSequence
airgapBuildStatus
}
}
releasedAt
sequence
channelSequence
airgapBuildStatus
}
}
`,
}
`

func (c *GraphQLClient) ListChannels(appID string) ([]types.Channel, error) {
response := GraphQLResponseListChannels{}

request := graphql.Request{
Query: listChannelsQuery,

Variables: map[string]interface{}{
"appId": appID,
Expand All @@ -121,26 +123,28 @@ func (c *GraphQLClient) ListChannels(appID string) ([]types.Channel, error) {
return channels, nil
}

const createChannelQuery = `
mutation createKotsChannel($appId: String!, $channelName: String!, $description: String) {
createKotsChannel(appId: $appId, channelName: $channelName, description: $description) {
id
name
description
currentVersion
currentReleaseDate
numReleases
created
updated
isDefault
isArchived
}
}
`

func (c *GraphQLClient) CreateChannel(appID string, name string, description string) (string, error) {
response := GraphQLResponseCreateChannel{}

request := graphql.Request{
Query: `
mutation createKotsChannel($appId: String!, $channelName: String!, $description: String) {
createKotsChannel(appId: $appId, channelName: $channelName, description: $description) {
id
name
description
currentVersion
currentReleaseDate
numReleases
created
updated
isDefault
isArchived
}
}
`,
Query: createChannelQuery,
Variables: map[string]interface{}{
"appId": appID,
"channelName": name,
Expand All @@ -160,7 +164,7 @@ func ArchiveChannel(appID string, channelID string) error {
return nil
}

var getKotsChannel = `
const getKotsChannel = `
query getKotsChannel($channelId: ID!) {
getKotsChannel(channelId: $channelId) {
id
Expand Down
20 changes: 11 additions & 9 deletions pkg/kotsclient/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,18 @@ type UpdateKotsRelease struct {
Config string `json:"spec,omitempty"`
}

const createReleaseQuery = `
mutation createKotsRelease($appId: ID!, $spec: String) {
createKotsRelease(appId: $appId, spec: $spec) {
sequence
}
}`

func (c *GraphQLClient) CreateRelease(appID string, multiyaml string) (*types.ReleaseInfo, error) {
response := GraphQLResponseKotsCreateRelease{}

request := graphql.Request{
Query: `
mutation createKotsRelease($appId: ID!, $spec: String) {
createKotsRelease(appId: $appId, spec: $spec) {
sequence
}
}`,
Query: createReleaseQuery,
Variables: map[string]interface{}{
"appId": appID,
"spec": multiyaml,
Expand All @@ -89,7 +91,7 @@ func (c *GraphQLClient) CreateRelease(appID string, multiyaml string) (*types.Re
return &releaseInfo, nil
}

var updateKotsRelease = `
const updateKotsRelease = `
mutation updateKotsRelease($appId: ID!, $spec: String!, $sequence: Int) {
updateKotsRelease(appId: $appId, spec: $spec, sequence: $sequence) {
sequence
Expand Down Expand Up @@ -117,7 +119,7 @@ func (c *GraphQLClient) UpdateRelease(appID string, sequence int64, multiyaml st
return nil
}

var allKotsReleases = `
const allKotsReleases = `
query allKotsReleases($appId: ID!, $pageSize: Int, $currentPage: Int) {
allKotsReleases(appId: $appId, pageSize: $pageSize, currentPage: $currentPage) {
sequence
Expand Down Expand Up @@ -188,7 +190,7 @@ func (c *GraphQLClient) ListReleases(appID string) ([]types.ReleaseInfo, error)
return releaseInfos, nil
}

var promoteKotsRelease = `
const promoteKotsRelease = `
mutation promoteKotsRelease($appId: ID!, $sequence: Int, $channelIds: [String], $versionLabel: String!, $releaseNotes: String) {
promoteKotsRelease(appId: $appId, sequence: $sequence, channelIds: $channelIds, versionLabel: $versionLabel, releaseNotes: $releaseNotes) {
sequence
Expand Down
14 changes: 8 additions & 6 deletions pkg/shipclient/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@ type ShipApp struct {
Channels []ShipChannel `json:"channel"`
}

func (c *GraphQLClient) ListApps() ([]types.AppAndChannels, error) {
response := GraphQLResponseListApps{}

request := graphql.Request{
Query: `
const listAppsQuery = `
query {
ship {
apps {
Expand All @@ -49,7 +45,13 @@ query {
}
}
}
}`,
}`

func (c *GraphQLClient) ListApps() ([]types.AppAndChannels, error) {
response := GraphQLResponseListApps{}

request := graphql.Request{
Query: listAppsQuery,

Variables: map[string]interface{}{},
}
Expand Down
28 changes: 16 additions & 12 deletions pkg/shipclient/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,7 @@ type ShipChannel struct {
CurrentVersion string `json:"currentVersion"`
}

func (c *GraphQLClient) ListChannels(appID string) ([]types.Channel, error) {
response := GraphQLResponseListChannels{}

request := graphql.Request{
Query: `
const listChannelsQuery = `
query getAppChannels($appId: ID!) {
getAppChannels(appId: $appId) {
id,
Expand Down Expand Up @@ -65,7 +61,13 @@ query getAppChannels($appId: ID!) {
semver
}
}
}`,
}`

func (c *GraphQLClient) ListChannels(appID string) ([]types.Channel, error) {
response := GraphQLResponseListChannels{}

request := graphql.Request{
Query: listChannelsQuery,

Variables: map[string]interface{}{
"appId": appID,
Expand All @@ -92,11 +94,7 @@ query getAppChannels($appId: ID!) {
return channels, nil
}

func (c *GraphQLClient) CreateChannel(appID string, name string, description string) error {
response := graphql.ResponseErrorOnly{}

request := graphql.Request{
Query: `
const createChannelQuery = `
mutation createChannel($appId: String!, $channelName: String!, $description: String) {
createChannel(appId: $appId, channelName: $channelName, description: $description) {
id,
Expand All @@ -111,7 +109,13 @@ mutation createChannel($appId: String!, $channelName: String!, $description: Str
isDefault,
isArchived
}
}`,
}`

func (c *GraphQLClient) CreateChannel(appID string, name string, description string) error {
response := graphql.ResponseErrorOnly{}

request := graphql.Request{
Query: createChannelQuery,
Variables: map[string]interface{}{
"appId": appID,
"channelName": name,
Expand Down
Loading

0 comments on commit 0176226

Please sign in to comment.