
Security News
Follow-up and Clarification on Recent Malicious Ruby Gems Campaign
A clarification on our recent research investigating 60 malicious Ruby gems.
Generate swift code for any specific GraphQL schema that provides query builders and response classes.
The code generator requires ruby version 2.1 or later.
Until this project is released, it is recommended to include it into a project as a git submodule.
$ git submodule https://github.com/Shopify/graphql_swift_gen.git
It is recommended to use bundler to install the code generators ruby package.
Add this line to your application's Gemfile:
gem 'graphql_swift_gen', path: 'graphql_swift_gen'
And then execute:
$ bundle
The generated code depends on support/Sources/GraphQL.swift from this repo which should be added to the project along with the generated code.
Create a script that generates the code for a GraphQL API
require 'graphql_swift_gen'
require 'graphql_schema'
require 'json'
introspection_result = File.read("graphql_schema.json")
schema = GraphQLSchema.new(JSON.parse(introspection_result))
GraphQLSwiftGen.new(schema,
nest_under: 'ExampleSchema',
custom_scalars: [
GraphQLSwiftGen::Scalar.new(
type_name: 'Money',
swift_type: 'NSDecimalNumber',
deserialize_expr: ->(expr) { "NSDecimalNumber(string: #{expr}, locale: GraphQL.posixLocale)" },
serialize_expr: ->(expr) { "#{expr}.description(withLocale: GraphQL.posixLocale)" },
),
]
).save("#{Dir.pwd}/../MyApp/Source")
That generated code depends on the GraphQLSupport package.
The generated code includes a query builder that can be used to create a GraphQL query in a type-safe mannar.
let queryString = ExampleSchema.buildQuerya { $0
.user { $0
.firstName()
.lastName()
}
}
The generated code also includes response classes that will deserialize the response and provide methods for accessing the field data with it already coerced to the correct type.
guard let response = try? GraphQLResponse<ExampleSchema.QueryRoot>(jsonData: response) else {
print("Invalid GraphQL response")
return
}
if let errors = response.errors {
for error in errors {
print("GraphQL error: \(error.message)")
}
}
if let data = response.data {
let user = data.user
print("\(user.firstName) \(user.lastName)")
}
After checking out the repo, run bundle
to install ruby dependencies.
Then, run rake test
to run the tests.
To install this gem onto your local machine, run bundle exec rake install
or reference it from a Gemfile using the path option
(e.g. gem 'graphql_swift_gen', path: '~/src/graphql_swift_gen'
).
See our contributing guidelines for more information.
The gem is available as open source under the terms of the MIT License.
FAQs
Unknown package
We found that graphql_swift_gen demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A clarification on our recent research investigating 60 malicious Ruby gems.
Security News
ESLint now supports parallel linting with a new --concurrency flag, delivering major speed gains and closing a 10-year-old feature request.
Research
/Security News
A malicious Go module posing as an SSH brute forcer exfiltrates stolen credentials to a Telegram bot controlled by a Russian-speaking threat actor.