vitrine-social
vitrine-social copied to clipboard
GraphQL
connected to #297
Essa é uma implementação dos handlers que existem usando a lib github.com/graphql-go/graphql
, não foram implementados os endpoints de contato/e-mail e afins por enquanto, para tentar evitar demorar mais com o PR que o humanamente aceitável.
Se puderem dar uma olhada (talvez testar o uso) eu agradeceria.
O GraphiQL foi alterado para suportar o envio do token de autorização:
Full Schema:
# source: http://localhost:8000/graphql
# timestamp: Fri Aug 03 2018 13:57:35 GMT-0300 (Horário Padrão de Brasília)
schema {
query: RootQuery
mutation: RootMutation
}
type Address {
city: String
complement: String
neighbordhood: String
number: String
state: String
street: String
zipcode: String
}
input AddressInput {
"""When set to true, will make the address without a complement"""
withoutComplement: Boolean = false
street: String
number: String
complement: String
neighbordhood: String
city: String
state: String
zipcode: String
}
type Category {
id: Int!
name: String!
needsCount: Int!
slug: String!
}
"""
The `Date` scalar type represents a Date with the format "yyyy-mm-dd". The Date is serialized as an string
"""
scalar Date
"""
The `DateTime` scalar represents a Date time string supported by the RFC 3339.
"""
scalar DateTime
type LoginResult {
organization: Organization
token: String!
}
type Need {
category: Category
createdAt: DateTime!
description: String
dueDate: Date
id: Int!
images: [NeedImage!]
organization: Organization
reachedQuantity: Int
requiredQuantity: Int
status: NeedStatus
title: String!
unit: String
updatedAt: DateTime
}
input NeedCreateInput {
unit: String!
dueDate: Date
categoryId: Int!
title: String!
description: String
requiredQuantity: Int = 0
reachedQuantity: Int = 0
}
type NeedCreatePayload {
need: Need
}
type NeedImage {
id: Int!
name: String!
url: String!
}
input NeedImageCreateInput {
needId: Int!
file: Upload!
}
type NeedImageCreatePayload {
needImage: NeedImage
}
input NeedImageDeleteInput {
needId: Int!
needImageId: Int!
}
type NeedImageDeletePayload {
need: Need
}
input NeedPatchInput {
title: String
description: String
requiredQuantity: Int
unit: String
categoryId: Int
status: NeedStatus
"""When set to true, will make the need without a description"""
withoutDescription: Boolean = false
"""When set to true, will make the need without date limit"""
withoutDueDate: Boolean = false
reachedQuantity: Int
dueDate: Date
}
"""Status of a Need"""
enum NeedStatus {
"""A inactive Need"""
INACTIVE
"""A active Need"""
ACTIVE
}
input NeedUpdateInput {
patch: NeedPatchInput!
id: Int!
}
type NeedUpdatePayload {
need: Need
}
type Organization {
about: String!
address: Address!
email: String!
id: Int!
images: [OrganizationImage]
logo: String
name: String!
needs(input: SearchOrganizationNeedsInput): PaginatedNeedsPayload
phone: String!
slug: String!
video: String!
website: String
}
type OrganizationImage {
id: Int!
name: String!
url: String!
}
input OrganizationImageCreateInput {
file: Upload!
}
type OrganizationImageCreatePayload {
organizationImage: OrganizationImage
}
input OrganizationImageDeleteInput {
organizationImageId: Int!
}
type OrganizationImageDeletePayload {
organization: Organization
}
input OrganizationUpdateInput {
phone: String
about: String
video: String
email: String
address: AddressInput
name: String
}
type OrganizationUpdatePayload {
organization: Organization
}
type PageInfo {
currentPage: Int!
totalPages: Int!
totalResults: Int!
}
type PaginatedNeedsPayload {
pageInfo: PageInfo
results: [Need!]
}
type ResetPasswordPayload {
organization: Organization
}
type RootMutation {
"""
Authenticate the user and returns a token and organization if succeded
"""
login(email: String!, password: String!): LoginResult
"""Mutations that need authentication"""
viewer: ViewerMutations
}
type RootQuery {
"""Return all Categories"""
allCategories: [Category]
"""Retrieves a Category by its ID"""
category(id: Int!): Category
"""Retrieves a Need by its Id"""
need(id: Int!): Need
"""Retrieves a Organization by its Id"""
organization(id: Int!): Organization
"""Search active needs on the database"""
search(input: SearchNeedsInput): PaginatedNeedsPayload
"""Authorized Organization"""
viewer: Organization
}
input SearchNeedsInput {
page: Int = 1
text: String
categories: [Int!]
organizationId: Int
status: NeedStatus
orderBy: SearchOrderBy
order: SearchOrder
}
"""Order will be accending or descending"""
enum SearchOrder {
ASC
DESC
}
"""Which kind of ordering will be used"""
enum SearchOrderBy {
"""Order by Need's ID"""
ID
"""Order by Last Need's Update date"""
UPDATED_AT
"""Order by Need's Creation date"""
CREATED_AT
}
input SearchOrganizationNeedsInput {
categories: [Int!]
orderBy: SearchOrderBy
status: NeedStatus
order: SearchOrder
page: Int = 1
text: String
}
input UpdatePasswordInput {
currentPassword: String!
newPassword: String!
}
type UpdatePasswordPayload {
organization: Organization
}
"""
The `Upload` scalar represents a uploaded file using "multipart/form-data" as
described in the spec:
(https://github.com/jaydenseric/graphql-multipart-request-spec/tree/v2.0.0)
"""
scalar Upload
type ViewerMutations {
"""Creates a need for the token Organization"""
needCreate(input: NeedCreateInput): NeedCreatePayload
"""Creates a image for the need"""
needImageCreate(input: NeedImageCreateInput): NeedImageCreatePayload
"""Deletes a image from the need"""
needImageDelete(input: NeedImageDeleteInput): NeedImageDeletePayload
"""Updates a need with the patch"""
needUpdate(input: NeedUpdateInput): NeedUpdatePayload
"""Creates a image for the current organization"""
organizationImageCreate(input: OrganizationImageCreateInput): OrganizationImageCreatePayload
"""Deletes a image from the current organization"""
organizationImageDelete(input: OrganizationImageDeleteInput): OrganizationImageDeletePayload
"""Updates Organization Profile"""
organizationUpdate(input: OrganizationUpdateInput): OrganizationUpdatePayload
"""Reset the Organizations password to a new password"""
resetPassword(newPassword: String!): ResetPasswordPayload
"""Updates the current user password"""
updatePassword(input: UpdatePasswordInput): UpdatePasswordPayload
}
Codecov Report
Merging #270 into master will increase coverage by
21.79%
. The diff coverage is75.9%
.
@@ Coverage Diff @@
## master #270 +/- ##
===========================================
+ Coverage 21.93% 43.72% +21.79%
===========================================
Files 31 47 +16
Lines 1468 2120 +652
===========================================
+ Hits 322 927 +605
- Misses 1110 1149 +39
- Partials 36 44 +8
Impacted Files | Coverage Δ | |
---|---|---|
server/handlers/json-structs.go | 77.77% <ø> (ø) |
:arrow_up: |
server/db/repo/search.go | 0% <0%> (ø) |
:arrow_up: |
server/db/repo/organization.go | 0% <0%> (ø) |
:arrow_up: |
server/db/repo/category.go | 0% <0%> (ø) |
:arrow_up: |
server/handlers/auth.go | 51.78% <0%> (-3.99%) |
:arrow_down: |
server/db/repo/need.go | 0% <0%> (ø) |
:arrow_up: |
server/graphql/organizationImageDeleteMutation.go | 100% <100%> (ø) |
|
server/graphql/needCreateMutation.go | 100% <100%> (ø) |
|
server/graphql/needImageDeleteMutation.go | 100% <100%> (ø) |
|
server/graphql/viewerMutation.go | 100% <100%> (ø) |
|
... and 49 more |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact)
,ø = not affected
,? = missing data
Powered by Codecov. Last update ed4864a...97fffc9. Read the comment docs.
Here is an overview of what got changed by this pull request:
Issues
======
- Added 4
Complexity increasing per file
==============================
- server/db/repo/organization.go 8
- server/graphql/organizationUpdateMutation.go 19
- server/graphql/viewerQuery.go 2
- server/graphql/needImageDeleteMutation.go 2
- server/graphql/needCreateMutation.go 4
- server/graphql/categoryQuery.go 4
- server/graphql/graphql_test.go 7
- server/graphql/loginMutation.go 4
- server/graphql/resetPasswordMutation.go 4
- server/graphql/organizationQuery.go 2
- server/graphql/allCategoriesQuery.go 2
- server/graphql/scalar.go 6
- server/graphql/needImageCreateMutation.go 3
- server/graphql/viewerMutation.go 1
- server/graphql/organizationImageDeleteMutation.go 2
- server/graphql/searchQuery.go 6
- server/graphql/graphiql-middleware.go 4
- server/graphql/graphql.go 3
- server/graphql/needQuery.go 10
- server/graphql/updatePasswordMutation.go 4
- server/graphql/needUpdateMutation.go 20
- server/graphql/organizationImageCreateMutation.go 3
See the complete overview on Codacy